From 604da4dedce63a1bebbb0734939ecc160e3c713a Mon Sep 17 00:00:00 2001 From: rohanjulka19 Date: Wed, 13 Jun 2018 13:47:03 +0530 Subject: [PATCH 01/15] Adding Implementation Class --- .../service/ImplementationManagerService.java | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/service/ImplementationManagerService.java diff --git a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/service/ImplementationManagerService.java b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/service/ImplementationManagerService.java new file mode 100644 index 00000000000..030425f6254 --- /dev/null +++ b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/service/ImplementationManagerService.java @@ -0,0 +1,39 @@ +package org.apache.syncope.ide.netbeans.service; + +import java.util.List; +import javax.ws.rs.core.Response; +import org.apache.syncope.client.lib.SyncopeClient; +import org.apache.syncope.client.lib.SyncopeClientFactoryBean; +import org.apache.syncope.common.lib.to.ImplementationTO; +import org.apache.syncope.common.lib.types.ImplementationType; +import org.apache.syncope.common.rest.api.service.ImplementationService; + +public class ImplementationManagerService { + + private final ImplementationService service ; + + public ImplementationManagerService(final String url, final String userName, final String password) { + SyncopeClient syncopeClient = new SyncopeClientFactoryBean().setAddress(url).create(userName, password); + service = syncopeClient.getService(ImplementationService.class); + } + + public List list(final ImplementationType type) { + return service.list(type); + } + + public ImplementationTO read(final ImplementationType type ,final String key) { + return service.read(type,key); + } + + public boolean create(final ImplementationTO implementationTO) { + return Response.Status.CREATED.getStatusCode() == service.create(implementationTO).getStatus(); + } + + public boolean delete(final ImplementationType type , String key) { + return Response.Status.NO_CONTENT.getStatusCode() == service.delete(type,key).getStatus(); + } + + public boolean update(final ImplementationTO implementationTO ) { + return Response.Status.NO_CONTENT.getStatusCode() == service.update(implementationTO).getStatus(); + } +} \ No newline at end of file From 25881d7b46c95b81ad776ce1026b2f275f69c4e3 Mon Sep 17 00:00:00 2001 From: rohanjulka19 Date: Wed, 13 Jun 2018 14:27:30 +0530 Subject: [PATCH 02/15] [SYNCOPE-1220] Added Groovy Implementation Class --- .../syncope/ide/netbeans/ResourceConnector.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/ResourceConnector.java b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/ResourceConnector.java index b7739fa9e79..c5a68c4d816 100644 --- a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/ResourceConnector.java +++ b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/ResourceConnector.java @@ -32,10 +32,14 @@ public final class ResourceConnector { private static ReportTemplateManagerService REPORT_TEMPLATE_MANAGER_SERVICE; + private static ImplementationManagerService IMPLEMENTATION_MANAGER_SERVICE; + private static final Object MAIL_TEMPLATE_MONITOR = new Object(); private static final Object REPORT_TEMPLATE_MONITOR = new Object(); + private static final Object IMPLEMENTATION_MONITOR = new Object(); + private ResourceConnector() { } @@ -61,6 +65,17 @@ public static ReportTemplateManagerService getReportTemplateManagerService() thr return REPORT_TEMPLATE_MANAGER_SERVICE; } + public static ImplementationManagerService getImplementationManagerService() throws IOException { + synchronized (IMPLEMENTATION_MONITOR) { + ConnectionParams connParams = getConnectionParams(); + IMPLEMENTATION_MANAGER_SERVICE = new ImplementationManagerService( + connParams.getUrl(), + connParams.getUsername(), + connParams.getPassword()); + } + return IMPLEMENTATION_MANAGER_SERVICE; + } + public static ConnectionParams getConnectionParams() { Preferences prefs = NbPreferences.forModule(ResourceExplorerTopComponent.class); return ConnectionParams.builder() From a05a1995ec7dec8dffa085a150ee6fa4315f3550 Mon Sep 17 00:00:00 2001 From: rohanjulka19 Date: Wed, 13 Jun 2018 14:41:17 +0530 Subject: [PATCH 03/15] [SYNCOPE-1220] Added functionality for listing Groovy Scripts --- .../syncope/ide/netbeans/PluginConstants.java | 2 ++ .../view/ResourceExplorerTopComponent.java | 35 ++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/PluginConstants.java b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/PluginConstants.java index ea2fd80b7d2..c1359bf3098 100644 --- a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/PluginConstants.java +++ b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/PluginConstants.java @@ -27,6 +27,8 @@ public final class PluginConstants { public static final String REPORT_XSLTS = "Report XSLTs"; + public static final String GROOVY_SCRIPTS = "Groovy Scripts"; + public static final String[] MAIL_TEMPLATE_FORMATS = { MailTemplateFormat.HTML.name(), MailTemplateFormat.TEXT.name() }; diff --git a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java index b2a01984a35..5893011b968 100644 --- a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java +++ b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java @@ -47,13 +47,16 @@ import org.apache.syncope.common.lib.SyncopeClientException; import org.apache.syncope.common.lib.to.MailTemplateTO; import org.apache.syncope.common.lib.to.ReportTemplateTO; +import org.apache.syncope.common.lib.to.ImplementationTO; import org.apache.syncope.common.lib.types.ClientExceptionType; import org.apache.syncope.common.lib.types.MailTemplateFormat; import org.apache.syncope.common.lib.types.ReportTemplateFormat; +import org.apache.syncope.common.lib.types.ImplementationType; import org.apache.syncope.ide.netbeans.PluginConstants; import org.apache.syncope.ide.netbeans.ResourceConnector; import org.apache.syncope.ide.netbeans.service.MailTemplateManagerService; import org.apache.syncope.ide.netbeans.service.ReportTemplateManagerService; +import org.apache.syncope.ide.netbeans.service.ImplementationManagerService; import org.netbeans.api.editor.EditorRegistry; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.settings.ConvertAsProperties; @@ -106,10 +109,14 @@ public final class ResourceExplorerTopComponent extends TopComponent { private final DefaultMutableTreeNode reportXslts; + private final DefaultMutableTreeNode groovyScripts; + private MailTemplateManagerService mailTemplateManagerService; private ReportTemplateManagerService reportTemplateManagerService; + private ImplementationManagerService implementationManagerService; + private Charset encodingPattern; public ResourceExplorerTopComponent() { @@ -123,6 +130,7 @@ public ResourceExplorerTopComponent() { visibleRoot = new DefaultMutableTreeNode(PluginConstants.ROOT_NAME); mailTemplates = new DefaultMutableTreeNode(PluginConstants.MAIL_TEMPLATES); reportXslts = new DefaultMutableTreeNode(PluginConstants.REPORT_XSLTS); + groovyScripts = new DefaultMutableTreeNode(PluginConstants.GROOVY_SCRIPTS); root.add(visibleRoot); initTemplatesTree(); } @@ -223,6 +231,7 @@ public void componentOpened() { try { mailTemplateManagerService = ResourceConnector.getMailTemplateManagerService(); reportTemplateManagerService = ResourceConnector.getReportTemplateManagerService(); + implementationManagerService = ResourceConnector.getImplementationManagerService(); // init tree, because on close it is reset initTemplatesTree(); // Load templates @@ -244,16 +253,17 @@ public boolean cancel() { progr.progress("Loading Templates."); addMailTemplates(); addReportXslts(); + addGroovyScripts(); progr.finish(); } - }; + }; REQUEST_PROCESSOR.post(tsk); } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage(), "Generic Error", JOptionPane.ERROR_MESSAGE); ServerDetailsView serverDetails = getRefreshServerDetails(); - } - + } + Runnable tsk = new Runnable() { @Override @@ -270,13 +280,14 @@ public boolean cancel() { progr.progress("Loading Templates."); addMailTemplates(); addReportXslts(); + addGroovyScripts(); progr.finish(); } }; RequestProcessor.getDefault().post(tsk); } - + @Override public void componentClosed() { // TODO add custom code on component closing @@ -312,6 +323,21 @@ private void addReportXslts() { treeModel.reload(); } + private void addGroovyScripts() { + for(ImplementationType type : ImplementationType.values()) + { + DefaultMutableTreeNode tempNode = new DefaultMutableTreeNode(type.toString()); + List scripts = implementationManagerService.list(type); + for(ImplementationTO script : scripts) { + tempNode.add(new DefaultMutableTreeNode( + script.getKey())); + } + groovyScripts.add(tempNode); + } + + treeModel.reload(); + } + private void rootRightClickAction(final MouseEvent evt) { JPopupMenu menu = new JPopupMenu(); JMenuItem refreshItem = new JMenuItem("Refresh Templates"); @@ -642,6 +668,7 @@ private void closeComponent() { private void initTemplatesTree() { visibleRoot.add(mailTemplates); visibleRoot.add(reportXslts); + visibleRoot.add(groovyScripts); treeModel.reload(); } From ee4f4a2347eef35b969332cbf4060a81b49b67c4 Mon Sep 17 00:00:00 2001 From: rohanjulka19 Date: Fri, 15 Jun 2018 00:56:52 +0530 Subject: [PATCH 04/15] [SYNCOPE-1220] Added Groovy Implementation Class --- .../java/org/apache/syncope/ide/netbeans/ResourceConnector.java | 1 + 1 file changed, 1 insertion(+) diff --git a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/ResourceConnector.java b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/ResourceConnector.java index c5a68c4d816..51df938d05a 100644 --- a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/ResourceConnector.java +++ b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/ResourceConnector.java @@ -23,6 +23,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.syncope.ide.netbeans.service.MailTemplateManagerService; import org.apache.syncope.ide.netbeans.service.ReportTemplateManagerService; +import org.apache.syncope.ide.netbeans.service.ImplementationManagerService; import org.apache.syncope.ide.netbeans.view.ResourceExplorerTopComponent; import org.openide.util.NbPreferences; From 3a74303af758aa233826f7236a9ef49c33cab87b Mon Sep 17 00:00:00 2001 From: rohanjulka19 Date: Fri, 15 Jun 2018 01:00:51 +0530 Subject: [PATCH 05/15] [SYNCOPE-1220] Added functionality for creating and deleting --- .../view/ResourceExplorerTopComponent.java | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java index 5893011b968..6ff9d9c4926 100644 --- a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java +++ b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java @@ -52,6 +52,7 @@ import org.apache.syncope.common.lib.types.MailTemplateFormat; import org.apache.syncope.common.lib.types.ReportTemplateFormat; import org.apache.syncope.common.lib.types.ImplementationType; +import org.apache.syncope.common.lib.types.ImplementationEngine; import org.apache.syncope.ide.netbeans.PluginConstants; import org.apache.syncope.ide.netbeans.ResourceConnector; import org.apache.syncope.ide.netbeans.service.MailTemplateManagerService; @@ -196,16 +197,21 @@ private void resourceExplorerTreeMouseClicked(final java.awt.event.MouseEvent ev } else if (evt.getButton() == MouseEvent.BUTTON3 && evt.getClickCount() == 1) { DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) resourceExplorerTree. getLastSelectedPathComponent(); + DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selectedNode.getParent(); + String parentNodeName = (String) parent.getUserObject(); String selectedNodeName = (String) selectedNode.getUserObject(); if (selectedNode.isLeaf() && !PluginConstants.ROOT_NAME.equals(selectedNodeName) && !PluginConstants.MAIL_TEMPLATES.equals(selectedNodeName) - && !PluginConstants.REPORT_XSLTS.equals(selectedNodeName)) { + && !PluginConstants.REPORT_XSLTS.equals(selectedNodeName) + && !PluginConstants.GROOVY_SCRIPTS.equals(parentNodeName)) { leafRightClickAction(evt, selectedNode); } else if (PluginConstants.MAIL_TEMPLATES.equals(selectedNodeName)) { folderRightClickAction(evt, mailTemplates); } else if (PluginConstants.REPORT_XSLTS.equals(selectedNodeName)) { folderRightClickAction(evt, reportXslts); + } else if(PluginConstants.GROOVY_SCRIPTS.equals(parentNodeName)){ + folderRightClickAction(evt,selectedNode); } else if (PluginConstants.ROOT_NAME.equals(selectedNodeName)) { rootRightClickAction(evt); } @@ -290,7 +296,8 @@ public boolean cancel() { @Override public void componentClosed() { - // TODO add custom code on component closing + // TODO add custom code on component + resetTree(); } void writeProperties(final java.util.Properties p) { @@ -334,7 +341,7 @@ private void addGroovyScripts() { } groovyScripts.add(tempNode); } - + treeModel.reload(); } @@ -390,6 +397,7 @@ private void folderRightClickAction(final MouseEvent evt, @Override public void actionPerformed(final ActionEvent e) { String name = JOptionPane.showInputDialog("Enter Name"); + DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); boolean added = false; if (!"exit".equals(e.getActionCommand())) { @@ -408,6 +416,13 @@ public void actionPerformed(final ActionEvent e) { } catch (IOException ex) { Exceptions.printStackTrace(ex); } + } else if((parent.getUserObject().equals(PluginConstants.GROOVY_SCRIPTS))) { + ImplementationTO newNode = new ImplementationTO(); + newNode.setKey(name); + newNode.setEngine(ImplementationEngine.GROOVY); + newNode.setType(getType((String)node.getUserObject())); + newNode.setBody("hello"); + added = implementationManagerService.create(newNode); } else { ReportTemplateTO reportTemplate = new ReportTemplateTO(); reportTemplate.setKey(name); @@ -455,13 +470,16 @@ public void actionPerformed(final ActionEvent e) { int result = JOptionPane.showConfirmDialog(null, "Are you sure to delete the item?"); if (result == JOptionPane.OK_OPTION) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); - boolean deleted; + boolean deleted = false; if (parent.getUserObject().equals(PluginConstants.MAIL_TEMPLATES)) { deleted = mailTemplateManagerService.delete((String) node.getUserObject()); - } else { + } else if(parent.getUserObject().equals(PluginConstants.REPORT_XSLTS)) { deleted = reportTemplateManagerService.delete((String) node.getUserObject()); + } else { + ImplementationType type = getType((String)parent.getUserObject()); + deleted = implementationManagerService.delete(type, (String) node.getUserObject()); } - if (deleted) { + if(deleted) { node.removeFromParent(); treeModel.reload(parent); } else { @@ -657,6 +675,17 @@ private void saveContent() { Exceptions.printStackTrace(e); } } + + private ImplementationType getType(String typeName){ + ImplementationType type = null ; + for(ImplementationType implType : ImplementationType.values()){ + if(implType.toString().equals(typeName)) { + type = implType ; + } + + } + return(type); + } private void closeComponent() { boolean isClosed = this.close(); @@ -676,6 +705,7 @@ private void resetTree() { visibleRoot.removeAllChildren(); mailTemplates.removeAllChildren(); reportXslts.removeAllChildren(); + groovyScripts.removeAllChildren(); treeModel.reload(); } From a071415caab0273c65aa13bcb6e5116141f89c11 Mon Sep 17 00:00:00 2001 From: rohanjulka19 Date: Mon, 2 Jul 2018 17:31:15 +0530 Subject: [PATCH 06/15] [SYNCOPE -1220] Function for modifying the groovy Scripts --- .../view/ResourceExplorerTopComponent.java | 68 +++++++++++++++++-- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java index 6ff9d9c4926..9cb09c2c65f 100644 --- a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java +++ b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java @@ -184,11 +184,15 @@ private void resourceExplorerTreeMouseClicked(final java.awt.event.MouseEvent ev String parentNodeName = parentNode == null ? null : String.valueOf(parentNode.getUserObject()); if (selectedNode.isLeaf() && StringUtils.isNotBlank(parentNodeName)) { String leafNodeName = (String) selectedNode.getUserObject(); + DefaultMutableTreeNode grandParentNode = (DefaultMutableTreeNode) parentNode.getParent(); + String grandParentNodeName = (String) grandParentNode.getUserObject(); try { if (PluginConstants.MAIL_TEMPLATES.equals(parentNodeName)) { openMailEditor(leafNodeName); } else if (PluginConstants.REPORT_XSLTS.equals(parentNodeName)) { openReportEditor(leafNodeName); + } else if (PluginConstants.GROOVY_SCRIPTS.equals(grandParentNodeName)) { + openScriptEditor(leafNodeName,parentNodeName); } } catch (IOException e) { Exceptions.printStackTrace(e); @@ -336,8 +340,10 @@ private void addGroovyScripts() { DefaultMutableTreeNode tempNode = new DefaultMutableTreeNode(type.toString()); List scripts = implementationManagerService.list(type); for(ImplementationTO script : scripts) { - tempNode.add(new DefaultMutableTreeNode( - script.getKey())); + if(script.getEngine() == ImplementationEngine.GROOVY) { + tempNode.add(new DefaultMutableTreeNode( + script.getKey())); + } } groovyScripts.add(tempNode); } @@ -418,11 +424,24 @@ public void actionPerformed(final ActionEvent e) { } } else if((parent.getUserObject().equals(PluginConstants.GROOVY_SCRIPTS))) { ImplementationTO newNode = new ImplementationTO(); + ImplementationType type = getType((String)node.getUserObject()); newNode.setKey(name); newNode.setEngine(ImplementationEngine.GROOVY); - newNode.setType(getType((String)node.getUserObject())); - newNode.setBody("hello"); - added = implementationManagerService.create(newNode); + newNode.setType(type); + String temp [] = type.toString().split("_"); + temp[0] = temp[0].substring(0,1).toUpperCase() + temp[0].substring(1).toLowerCase(); + temp[1] = temp[1].substring(0,1).toUpperCase() + temp[1].substring(1).toLowerCase(); + temp[0] = temp[0] + temp[1]; + try { + newNode.setBody(IOUtils.toString( + getClass().getResourceAsStream("/org/apache/syncope/ide/netbeans/implementations/My" + + temp[0] + ".groovy"))); + added = implementationManagerService.create(newNode); + openScriptEditor(name,(String)node.getUserObject()); + } catch(Exception ex) + { + Exceptions.printStackTrace(ex); + } } else { ReportTemplateTO reportTemplate = new ReportTemplateTO(); reportTemplate.setKey(name); @@ -565,6 +584,34 @@ public void propertyChange(final PropertyChangeEvent evt) { } } + private void openScriptEditor(final String name , final String type) throws IOException { + ImplementationTO node = implementationManagerService.read(getType(type),name); + String groovyScriptsDirName = System.getProperty("java.io.tmpdir") + "/Groovy/" + node.getType().toString() + "/"; + File groovyScriptsDir = new File(groovyScriptsDirName); + if (!groovyScriptsDir.exists()) { + groovyScriptsDir.mkdirs(); + } + File file = new File(groovyScriptsDirName + name + ".groovy" ); + FileWriter fw = new FileWriter(file); + fw.write(node.getBody()); + fw.flush(); + FileObject fob = FileUtil.toFileObject(file.getAbsoluteFile()); + DataObject data = DataObject.find(fob); + data.getLookup().lookup(OpenCookie.class).open(); + data.addPropertyChangeListener(new PropertyChangeListener() { + + @Override + public void propertyChange(final PropertyChangeEvent evt) { + if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) { + //save item remotely + LOG.info(String.format("Saving Report template [%s]", name)); + saveContent(); + } + } + }); + + } + private void openReportEditor(final String name) throws IOException { String formatStr = (String) JOptionPane.showInputDialog(null, "Select File Format", "File format", JOptionPane.QUESTION_MESSAGE, null, @@ -641,8 +688,9 @@ private void saveContent() { Document document = ed.getDocument(); String content = document.getText(0, document.getLength()); String path = (String) document.getProperty(Document.TitleProperty); - String[] temp = path.split(File.separator); + String[] temp = path.split(File.separator.replace("\\","\\\\")); String name = temp[temp.length - 1]; + String fileName = temp[temp.length - 3]; String templateType = temp[temp.length - 2]; temp = name.split("\\."); String format = temp[1]; @@ -666,11 +714,17 @@ private void saveContent() { reportTemplateManagerService.setFormat(key, ReportTemplateFormat.FO, IOUtils.toInputStream(content, encodingPattern)); - } else { + } else if(format.equals("csv")) { reportTemplateManagerService.setFormat(key, ReportTemplateFormat.CSV, IOUtils.toInputStream(content, encodingPattern)); } + else if(fileName.equals("Groovy")) { + LOG.info("Setting groovy"); + ImplementationTO node = implementationManagerService.read(getType(templateType),key); + node.setBody(content); + implementationManagerService.update(node); + } } catch (BadLocationException e) { Exceptions.printStackTrace(e); } From e5c9e42f76a83c601abacd65b0f6ca8b731e4ab3 Mon Sep 17 00:00:00 2001 From: rohanjulka19 Date: Mon, 2 Jul 2018 17:33:11 +0530 Subject: [PATCH 07/15] [SYNCOPE-1220] Added Default Groovy Scripts --- ide/netbeans/pom.xml | 1 + .../implementations/MyAccountRule.groovy | 29 +++++ .../implementations/MyItemTransformer.groovy | 46 +++++++ .../implementations/MyLogicActions.groovy | 38 ++++++ .../implementations/MyPasswordRule.groovy | 28 ++++ .../MyPropagationActions.groovy | 43 ++++++ .../implementations/MyPullActions.groovy | 122 ++++++++++++++++++ .../MyPullCorrelationRule.groovy | 32 +++++ .../implementations/MyPushActions.groovy | 112 ++++++++++++++++ .../MyRecipientsProvider.groovy | 31 +++++ .../MyReconFilterBuilder.groovy | 30 +++++ .../implementations/MyReportlet.groovy | 30 +++++ .../MySchedTaskJobDelegate.groovy | 31 +++++ .../implementations/MyValidator.groovy | 34 +++++ 14 files changed, 607 insertions(+) create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyAccountRule.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyItemTransformer.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyLogicActions.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPasswordRule.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPropagationActions.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPullActions.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPullCorrelationRule.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPushActions.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyRecipientsProvider.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyReconFilterBuilder.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyReportlet.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MySchedTaskJobDelegate.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyValidator.groovy diff --git a/ide/netbeans/pom.xml b/ide/netbeans/pom.xml index 0ab56292352..af1aa3ea33b 100644 --- a/ide/netbeans/pom.xml +++ b/ide/netbeans/pom.xml @@ -176,6 +176,7 @@ under the License. false org/apache/syncope/**/*.png + org/apache/syncope/**/*.groovy diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyAccountRule.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyAccountRule.groovy new file mode 100644 index 00000000000..978e76db1e8 --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyAccountRule.groovy @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.persistence.api.dao.AccountRule +import org.apache.syncope.core.persistence.api.entity.user.User + +@CompileStatic +class MyAccountRule implements AccountRule { + + void enforce(User user) { + } + +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyItemTransformer.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyItemTransformer.groovy new file mode 100644 index 00000000000..fd4b5d41cc2 --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyItemTransformer.groovy @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.common.lib.to.EntityTO +import org.apache.syncope.core.persistence.api.entity.Entity +import org.apache.syncope.core.persistence.api.entity.PlainAttrValue +import org.apache.syncope.core.persistence.api.entity.resource.Item +import org.apache.syncope.core.provisioning.api.data.ItemTransformer + +@CompileStatic +class MyItemTransformer implements ItemTransformer { + + @Override + List beforePropagation( + Item item, + Entity entity, + List values) { + + return values; + } + + @Override + List beforePull( + Item item, + EntityTO entityTO, + List values) { + + return values; + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyLogicActions.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyLogicActions.groovy new file mode 100644 index 00000000000..df22aa231bf --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyLogicActions.groovy @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.common.lib.patch.AnyPatch +import org.apache.syncope.common.lib.patch.AttrPatch +import org.apache.syncope.common.lib.to.AnyTO +import org.apache.syncope.common.lib.to.AttrTO +import org.apache.syncope.core.provisioning.api.LogicActions + +@CompileStatic +class MyLogicActions implements LogicActions { + + @Override + A beforeCreate(final A input) { + return input; + } + + @Override + M beforeUpdate(final M input) { + return input; + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPasswordRule.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPasswordRule.groovy new file mode 100644 index 00000000000..dab38baca8a --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPasswordRule.groovy @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.persistence.api.dao.PasswordRule +import org.apache.syncope.core.persistence.api.entity.user.User + +@CompileStatic +class MyPasswordRule implements PasswordRule { + + void enforce(User user) { + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPropagationActions.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPropagationActions.groovy new file mode 100644 index 00000000000..6a24777af2e --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPropagationActions.groovy @@ -0,0 +1,43 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.persistence.api.entity.task.PropagationTask +import org.apache.syncope.core.persistence.api.entity.task.TaskExec +import org.apache.syncope.core.provisioning.api.propagation.PropagationActions +import org.identityconnectors.framework.common.objects.ConnectorObject + +@CompileStatic +class MyPropagationActions implements PropagationActions { + + @Override + void before(PropagationTask task, ConnectorObject beforeObj) { + // do nothing + } + + @Override + void onError(PropagationTask task, TaskExec execution, Exception error) { + // do nothing + } + + @Override + void after(PropagationTask task, TaskExec execution, ConnectorObject afterObj) { + // do nothing + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPullActions.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPullActions.groovy new file mode 100644 index 00000000000..893e7a97f89 --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPullActions.groovy @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.common.lib.patch.AnyPatch +import org.apache.syncope.common.lib.to.EntityTO +import org.apache.syncope.core.persistence.api.entity.task.ProvisioningTask +import org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException +import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningActions +import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningProfile +import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport +import org.apache.syncope.core.provisioning.api.pushpull.PullActions +import org.identityconnectors.framework.common.objects.SyncDelta +import org.quartz.JobExecutionException + +@CompileStatic +class MyPullActions implements PullActions { + + @Override + SyncDelta preprocess(SyncDelta delta) { + return delta; + } + + @Override + void beforeProvision( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity) throws JobExecutionException { + + } + + @Override + void beforeAssign( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity) throws JobExecutionException { + + } + + @Override + void beforeUnassign( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity) throws JobExecutionException { + + } + + @Override + void beforeDeprovision( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity) throws JobExecutionException { + + } + + @Override + void beforeUnlink( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity) throws JobExecutionException { + + } + + @Override + void beforeLink( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity) throws JobExecutionException { + + } + + @Override +

void beforeUpdate( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity, + P anyPatch) throws JobExecutionException { + + } + + @Override + void beforeDelete( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity) throws JobExecutionException { + + } + + @Override + void after( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity, + ProvisioningReport result) throws JobExecutionException { + + // do nothing + } + + @Override + IgnoreProvisionException onError( + ProvisioningProfile profile, + SyncDelta delta, + Exception e) throws JobExecutionException { + + return null; + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPullCorrelationRule.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPullCorrelationRule.groovy new file mode 100644 index 00000000000..bb56ebe04e7 --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPullCorrelationRule.groovy @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.persistence.api.dao.PullCorrelationRule +import org.apache.syncope.core.persistence.api.dao.search.SearchCond +import org.apache.syncope.core.persistence.api.entity.resource.Provision +import org.identityconnectors.framework.common.objects.ConnectorObject + +@CompileStatic +class MyPullCorrelationRule implements PullCorrelationRule { + + @Override + SearchCond getSearchCond(ConnectorObject connObj, Provision provision) { + + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPushActions.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPushActions.groovy new file mode 100644 index 00000000000..dad420636fd --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPushActions.groovy @@ -0,0 +1,112 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.persistence.api.entity.Entity +import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningProfile +import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport +import org.apache.syncope.core.provisioning.api.pushpull.PushActions +import org.quartz.JobExecutionException + +@CompileStatic +class MyPushActions implements PushActions { + + @Override + Entity beforeAssign( + ProvisioningProfile profile, + Entity entity) throws JobExecutionException { + + return entity; + } + + @Override + Entity beforeProvision( + ProvisioningProfile profile, + Entity entity) throws JobExecutionException { + + return entity; + } + + @Override + Entity beforeUpdate( + ProvisioningProfile profile, + Entity entity) throws JobExecutionException { + + return entity; + } + + @Override + Entity beforeLink( + ProvisioningProfile profile, + Entity entity) throws JobExecutionException { + + return entity; + } + + @Override + Entity beforeUnlink( + ProvisioningProfile profile, + Entity entity) throws JobExecutionException { + + return entity; + } + + @Override + Entity beforeUnassign( + ProvisioningProfile profile, + Entity entity) throws JobExecutionException { + + return entity; + } + + @Override + Entity beforeDeprovision( + ProvisioningProfile profile, + Entity entity) throws JobExecutionException { + + return entity; + } + + @Override + Entity beforeDelete( + ProvisioningProfile profile, + Entity entity) throws JobExecutionException { + + return entity; + } + + @Override + void onError( + ProvisioningProfile profile, + Entity entity, + ProvisioningReport result, + Exception error) throws JobExecutionException { + + // do nothing + } + + @Override + void after( + ProvisioningProfile profile, + Entity entity, + ProvisioningReport result) throws JobExecutionException { + + // do nothing + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyRecipientsProvider.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyRecipientsProvider.groovy new file mode 100644 index 00000000000..d118861800c --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyRecipientsProvider.groovy @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.persistence.api.attrvalue.validation.Validator +import org.apache.syncope.core.persistence.api.entity.Notification +import org.apache.syncope.core.provisioning.api.notification.RecipientsProvider + +@CompileStatic +class MyRecipientsProvider implements RecipientsProvider { + + @Override + Set provideRecipients(Notification notification) { + return Collections.emptyList(); + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyReconFilterBuilder.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyReconFilterBuilder.groovy new file mode 100644 index 00000000000..b19b88e66aa --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyReconFilterBuilder.groovy @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.provisioning.api.pushpull.ReconFilterBuilder +import org.identityconnectors.framework.common.objects.filter.Filter + +@CompileStatic +class MyReconFilterBuilder implements ReconFilterBuilder { + + @Override + Filter build() { + return PASS_THROUGH; + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyReportlet.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyReportlet.groovy new file mode 100644 index 00000000000..07447c21cb6 --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyReportlet.groovy @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.persistence.api.attrvalue.validation.Validator +import org.apache.syncope.core.persistence.api.dao.Reportlet +import org.xml.sax.SAXException + +@CompileStatic +class MyReportlet implements Reportlet { + + @Override + void extract(ContentHandler handler) throws SAXException { + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MySchedTaskJobDelegate.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MySchedTaskJobDelegate.groovy new file mode 100644 index 00000000000..3356319b044 --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MySchedTaskJobDelegate.groovy @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.provisioning.api.job.SchedTaskJobDelegate +import org.quartz.JobExecutionContext +import org.quartz.JobExecutionException + +@CompileStatic +class MySchedTaskJobDelegate implements SchedTaskJobDelegate { + + @Override + void execute(String taskKey, boolean dryRun, JobExecutionContext context) throws JobExecutionException { + + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyValidator.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyValidator.groovy new file mode 100644 index 00000000000..b0c3e377501 --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyValidator.groovy @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.persistence.api.attrvalue.validation.Validator +import org.apache.syncope.core.persistence.api.entity.PlainAttrValue +import org.apache.syncope.core.persistence.api.entity.PlainSchema + +@CompileStatic +class MyValidator implements Validator { + + @Override + void setSchema(PlainSchema schema) { + } + + @Override + void validate(String value, PlainAttrValue attrValue) { + } +} From 2996f28e90319bb31dea3054ddcef4249d9527b3 Mon Sep 17 00:00:00 2001 From: rohanjulka19 Date: Tue, 10 Jul 2018 05:25:33 +0530 Subject: [PATCH 08/15] [SYNCOPE - 1220] Errors Fixed --- .../view/ResourceExplorerTopComponent.java | 32 +++---------------- 1 file changed, 5 insertions(+), 27 deletions(-) diff --git a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java index 9cb09c2c65f..b073954bc00 100644 --- a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java +++ b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java @@ -272,32 +272,9 @@ public boolean cancel() { } catch (Exception e) { JOptionPane.showMessageDialog(null, e.getMessage(), "Generic Error", JOptionPane.ERROR_MESSAGE); ServerDetailsView serverDetails = getRefreshServerDetails(); - } - - Runnable tsk = new Runnable() { - - @Override - public void run() { - final ProgressHandle progr = ProgressHandle.createHandle("Loading Templates", new Cancellable() { - - @Override - public boolean cancel() { - return true; - } - }); - - progr.start(); - progr.progress("Loading Templates."); - addMailTemplates(); - addReportXslts(); - addGroovyScripts(); - progr.finish(); - } - - }; - RequestProcessor.getDefault().post(tsk); + } + } - @Override public void componentClosed() { // TODO add custom code on component @@ -307,7 +284,7 @@ public void componentClosed() { void writeProperties(final java.util.Properties p) { // better to version settings since initial version as advocated at // http://wiki.apidesign.org/wiki/PropertyFiles - p.setProperty("version", "1.0"); + p.setProperty("version", "1.0"); // TODO store your settings } @@ -338,6 +315,7 @@ private void addGroovyScripts() { for(ImplementationType type : ImplementationType.values()) { DefaultMutableTreeNode tempNode = new DefaultMutableTreeNode(type.toString()); + if(type.toString().equals("PUSH_CORRELATION_RULE")) continue ; // Temporary Solution List scripts = implementationManagerService.list(type); for(ImplementationTO script : scripts) { if(script.getEngine() == ImplementationEngine.GROOVY) { @@ -724,7 +702,7 @@ else if(fileName.equals("Groovy")) { ImplementationTO node = implementationManagerService.read(getType(templateType),key); node.setBody(content); implementationManagerService.update(node); - } + } } catch (BadLocationException e) { Exceptions.printStackTrace(e); } From d724e19d8af878a4ae4323f1d03e5100cc5faa74 Mon Sep 17 00:00:00 2001 From: rohanjulka19 Date: Tue, 10 Jul 2018 08:01:31 +0530 Subject: [PATCH 09/15] [SYNCOPE-1220] Fixed Errors --- .../view/ResourceExplorerTopComponent.java | 67 +++++++++++++++++-- 1 file changed, 60 insertions(+), 7 deletions(-) diff --git a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java index b073954bc00..2bcc4ea9779 100644 --- a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java +++ b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java @@ -273,7 +273,7 @@ public boolean cancel() { JOptionPane.showMessageDialog(null, e.getMessage(), "Generic Error", JOptionPane.ERROR_MESSAGE); ServerDetailsView serverDetails = getRefreshServerDetails(); } - + } @Override public void componentClosed() { @@ -406,14 +406,67 @@ public void actionPerformed(final ActionEvent e) { newNode.setKey(name); newNode.setEngine(ImplementationEngine.GROOVY); newNode.setType(type); - String temp [] = type.toString().split("_"); - temp[0] = temp[0].substring(0,1).toUpperCase() + temp[0].substring(1).toLowerCase(); - temp[1] = temp[1].substring(0,1).toUpperCase() + temp[1].substring(1).toLowerCase(); - temp[0] = temp[0] + temp[1]; + String templateClassName = null; + switch (type) { + case REPORTLET: + templateClassName = "MyReportlet"; + break; + + case ACCOUNT_RULE: + templateClassName = "MyAccountRule"; + break; + + case PASSWORD_RULE: + templateClassName = "MyPasswordRule"; + break; + + case ITEM_TRANSFORMER: + templateClassName = "MyItemTransformer"; + break; + + case TASKJOB_DELEGATE: + templateClassName = "MySchedTaskJobDelegate"; + break; + + case RECON_FILTER_BUILDER: + templateClassName = "MyReconFilterBuilder"; + break; + + case LOGIC_ACTIONS: + templateClassName = "MyLogicActions"; + break; + + case PROPAGATION_ACTIONS: + templateClassName = "MyPropagationActions"; + break; + + case PULL_ACTIONS: + templateClassName = "MyPullActions"; + break; + + case PUSH_ACTIONS: + templateClassName = "MyPushActions"; + break; + + case PULL_CORRELATION_RULE: + templateClassName = "MyPullCorrelationRule"; + break; + + case VALIDATOR: + templateClassName = "MyValidator"; + break; + + case RECIPIENTS_PROVIDER: + templateClassName = "MyRecipientsProvider"; + break; + + default: + } + LOG.info(templateClassName); try { newNode.setBody(IOUtils.toString( - getClass().getResourceAsStream("/org/apache/syncope/ide/netbeans/implementations/My" - + temp[0] + ".groovy"))); + getClass().getResourceAsStream("/org/apache/syncope/ide/netbeans/implementations/" + + templateClassName + ".groovy"))); added = implementationManagerService.create(newNode); openScriptEditor(name,(String)node.getUserObject()); } catch(Exception ex) From 4c15741d82e2157c437502ebbfad36643f0b24f1 Mon Sep 17 00:00:00 2001 From: rohanjulka19 Date: Thu, 9 Aug 2018 15:58:29 +0530 Subject: [PATCH 10/15] [SYNCOPE-1220] Fixed Errors --- .../view/ResourceExplorerTopComponent.java | 150 ++++++++++-------- 1 file changed, 85 insertions(+), 65 deletions(-) diff --git a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java index 2bcc4ea9779..3d923bdc4b1 100644 --- a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java +++ b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java @@ -196,7 +196,7 @@ private void resourceExplorerTreeMouseClicked(final java.awt.event.MouseEvent ev } } catch (IOException e) { Exceptions.printStackTrace(e); - } + } } } else if (evt.getButton() == MouseEvent.BUTTON3 && evt.getClickCount() == 1) { DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) resourceExplorerTree. @@ -269,10 +269,13 @@ public boolean cancel() { }; REQUEST_PROCESSOR.post(tsk); - } catch (Exception e) { + } catch (IOException e) { JOptionPane.showMessageDialog(null, e.getMessage(), "Generic Error", JOptionPane.ERROR_MESSAGE); ServerDetailsView serverDetails = getRefreshServerDetails(); } + catch(Exception ex) { + getRefreshServerDetails().setVisible(true); + } } @Override @@ -314,11 +317,12 @@ private void addReportXslts() { private void addGroovyScripts() { for(ImplementationType type : ImplementationType.values()) { - DefaultMutableTreeNode tempNode = new DefaultMutableTreeNode(type.toString()); - if(type.toString().equals("PUSH_CORRELATION_RULE")) continue ; // Temporary Solution + String implType = type.toString(); + DefaultMutableTreeNode tempNode = new DefaultMutableTreeNode(implType.toString()); + if(implType.equals("JWT_SSO_PROVIDER") || implType.equals("AUDIT_APPENDER") ) continue ; List scripts = implementationManagerService.list(type); for(ImplementationTO script : scripts) { - if(script.getEngine() == ImplementationEngine.GROOVY) { + if(script.getEngine() == ImplementationEngine.GROOVY) { tempNode.add(new DefaultMutableTreeNode( script.getKey())); } @@ -380,12 +384,16 @@ private void folderRightClickAction(final MouseEvent evt, @Override public void actionPerformed(final ActionEvent e) { - String name = JOptionPane.showInputDialog("Enter Name"); + try { + String name = "" ; + while(name.equals("")) + name = JOptionPane.showInputDialog("Enter Name"); DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); 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); @@ -395,11 +403,7 @@ public void actionPerformed(final ActionEvent e) { mailTemplateManagerService.setFormat(name, MailTemplateFormat.TEXT, IOUtils.toInputStream("//Enter Content here", encodingPattern)); - try { - openMailEditor(name); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } + openMailEditor(name); } else if((parent.getUserObject().equals(PluginConstants.GROOVY_SCRIPTS))) { ImplementationTO newNode = new ImplementationTO(); ImplementationType type = getType((String)node.getUserObject()); @@ -452,6 +456,10 @@ public void actionPerformed(final ActionEvent e) { templateClassName = "MyPullCorrelationRule"; break; + case PUSH_CORRELATION_RULE: + templateClassName = "MyPushCorrelationRule"; + break; + case VALIDATOR: templateClassName = "MyValidator"; break; @@ -461,18 +469,13 @@ public void actionPerformed(final ActionEvent e) { break; default: - } + } LOG.info(templateClassName); - try { newNode.setBody(IOUtils.toString( getClass().getResourceAsStream("/org/apache/syncope/ide/netbeans/implementations/" + templateClassName + ".groovy"))); added = implementationManagerService.create(newNode); openScriptEditor(name,(String)node.getUserObject()); - } catch(Exception ex) - { - Exceptions.printStackTrace(ex); - } } else { ReportTemplateTO reportTemplate = new ReportTemplateTO(); reportTemplate.setKey(name); @@ -486,11 +489,7 @@ public void actionPerformed(final ActionEvent e) { reportTemplateManagerService.setFormat(name, ReportTemplateFormat.HTML, IOUtils.toInputStream("//Enter content here", encodingPattern)); - try { openReportEditor(name); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } } if (added) { @@ -501,7 +500,16 @@ public void actionPerformed(final ActionEvent e) { null, "Error while creating new element", "Error", JOptionPane.ERROR_MESSAGE); } } + }catch(SyncopeClientException excp) { + JOptionPane.showMessageDialog(null, excp.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); } + catch(IOException | NullPointerException ex) { + JOptionPane.showMessageDialog(null ,ex.getMessage(),"Error", JOptionPane.ERROR_MESSAGE); + } + catch(Exception exc) { + getRefreshServerDetails().setVisible(true); + } + } }); menu.show(evt.getComponent(), evt.getX(), evt.getY()); @@ -520,14 +528,18 @@ public void actionPerformed(final ActionEvent e) { int result = JOptionPane.showConfirmDialog(null, "Are you sure to delete the item?"); if (result == JOptionPane.OK_OPTION) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); + String nodeName = (String) node.getUserObject() ; boolean deleted = false; + boolean fileDeleted = false ; + String tempFilePath = "" ; + try { if (parent.getUserObject().equals(PluginConstants.MAIL_TEMPLATES)) { - deleted = mailTemplateManagerService.delete((String) node.getUserObject()); + deleted = mailTemplateManagerService.delete(nodeName); } else if(parent.getUserObject().equals(PluginConstants.REPORT_XSLTS)) { - deleted = reportTemplateManagerService.delete((String) node.getUserObject()); + deleted = reportTemplateManagerService.delete(nodeName); } else { ImplementationType type = getType((String)parent.getUserObject()); - deleted = implementationManagerService.delete(type, (String) node.getUserObject()); + deleted = implementationManagerService.delete(type, nodeName); } if(deleted) { node.removeFromParent(); @@ -536,6 +548,13 @@ public void actionPerformed(final ActionEvent e) { JOptionPane.showMessageDialog( null, "Error while deleting new element", "Error", JOptionPane.ERROR_MESSAGE); } + } catch(SyncopeClientException exc) { + JOptionPane.showMessageDialog( + null, exc.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); + } + catch (Exception ex) { + getRefreshServerDetails().setVisible(true); + } } } }); @@ -554,7 +573,7 @@ private void openMailEditor(final String name) throws IOException { String type = null; InputStream is = null; - try { + try { switch (format) { case HTML: type = "html"; @@ -567,25 +586,7 @@ private void openMailEditor(final String name) throws IOException { default: LOG.log(Level.SEVERE, String.format("Format [%s] not supported", format)); break; - } - } catch (SyncopeClientException e) { - LOG.log(Level.SEVERE, - String.format("Unable to get [%s] mail template in [%s] format", name, format), e); - if (ClientExceptionType.NotFound.equals(e.getType())) { - LOG.log(Level.SEVERE, String.format( - "Report template in [%s] format not found, create an empty one", format)); - } else { - JOptionPane.showMessageDialog( - null, String.format("Unable to get [%s] report template in [%s] format", name, format), - "Connection Error", JOptionPane.ERROR_MESSAGE); - } - } catch (Exception e) { - LOG.log(Level.SEVERE, - String.format("Unable to get [%s] mail template in [%s] format", name, format), e); - JOptionPane.showMessageDialog( - null, String.format("Unable to get [%s] mail template in [%s] format", name, format), "Error", - JOptionPane.ERROR_MESSAGE); - } + } String content = is == null ? StringUtils.EMPTY : IOUtils.toString(is, encodingPattern); String mailTemplatesDirName = System.getProperty("java.io.tmpdir") + "/Templates/Mail/"; @@ -612,10 +613,22 @@ public void propertyChange(final PropertyChangeEvent evt) { } } }); - } + } catch (SyncopeClientException ex) { + JOptionPane.showMessageDialog( + null, ex.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); + } + catch(IOException | NullPointerException excp) { + JOptionPane.showMessageDialog(null ,excp.getMessage(), "Error" ,JOptionPane.ERROR_MESSAGE); + } + catch (Exception ex) { + LOG.info("The Exception is"+ ex); + getRefreshServerDetails().setVisible(true); + } + } } private void openScriptEditor(final String name , final String type) throws IOException { + try { ImplementationTO node = implementationManagerService.read(getType(type),name); String groovyScriptsDirName = System.getProperty("java.io.tmpdir") + "/Groovy/" + node.getType().toString() + "/"; File groovyScriptsDir = new File(groovyScriptsDirName); @@ -635,12 +648,23 @@ private void openScriptEditor(final String name , final String type) throws IOEx public void propertyChange(final PropertyChangeEvent evt) { if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) { //save item remotely - LOG.info(String.format("Saving Report template [%s]", name)); + LOG.info(String.format("Saving Groovy template [%s]", name)); saveContent(); } } }); + } catch (SyncopeClientException ex) { + JOptionPane.showMessageDialog( + null, ex.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); + } + catch(IOException | NullPointerException excp) { + JOptionPane.showMessageDialog(null ,excp.getMessage(), "Error" ,JOptionPane.ERROR_MESSAGE); + } + catch (Exception ex) { + LOG.info("The Exception is"+ ex); + getRefreshServerDetails().setVisible(true); + } } private void openReportEditor(final String name) throws IOException { @@ -651,7 +675,7 @@ private void openReportEditor(final String name) throws IOException { ReportTemplateFormat format = ReportTemplateFormat.valueOf(formatStr); InputStream is = null; - try { + try { switch (format) { case HTML: is = (InputStream) reportTemplateManagerService.getFormat(name, ReportTemplateFormat.HTML); @@ -666,24 +690,6 @@ private void openReportEditor(final String name) throws IOException { LOG.log(Level.SEVERE, String.format("Format [%s] not supported", format)); break; } - } catch (SyncopeClientException e) { - LOG.log(Level.SEVERE, String.format("Unable to get [%s] report template in [%s] format", name, format), - e); - if (ClientExceptionType.NotFound.equals(e.getType())) { - LOG.log(Level.SEVERE, String.format( - "Report template [%s] not found, create an empty one", name)); - } else { - JOptionPane.showMessageDialog( - null, String.format("Unable to get [%s] report template in [%s] format", name, format), - "Connection Error", JOptionPane.ERROR_MESSAGE); - } - } catch (Exception e) { - LOG.log(Level.SEVERE, String.format("Unable to get [%s] report template in [%s] format", name, format), - e); - JOptionPane.showMessageDialog( - null, String.format("Unable to get [%s] report template in [%s] format", name, format), - "Generic Error", JOptionPane.ERROR_MESSAGE); - } String content = is == null ? StringUtils.EMPTY : IOUtils.toString(is, encodingPattern); String reportTemplatesDirName = System.getProperty("java.io.tmpdir") + "/Templates/Report/"; @@ -710,6 +716,17 @@ public void propertyChange(final PropertyChangeEvent evt) { } } }); + } catch (SyncopeClientException ex) { + JOptionPane.showMessageDialog( + null, ex.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); + } + catch(IOException | NullPointerException excp) { + JOptionPane.showMessageDialog(null ,excp.getMessage(), "Error" ,JOptionPane.ERROR_MESSAGE); + } + catch (Exception ex) { + LOG.info("The Exception is"+ ex); + getRefreshServerDetails().setVisible(true); + } } } @@ -759,6 +776,9 @@ else if(fileName.equals("Groovy")) { } catch (BadLocationException e) { Exceptions.printStackTrace(e); } + catch (Exception e) { + getRefreshServerDetails().setVisible(true); + } } private ImplementationType getType(String typeName){ From 81947a5b9eb24c8a9326a07f799b13c2aee34568 Mon Sep 17 00:00:00 2001 From: rohanjulka19 Date: Tue, 14 Aug 2018 02:29:39 +0530 Subject: [PATCH 11/15] [SYNCOPE -1220] Fixed Checkstyle errors --- .../service/ImplementationManagerService.java | 30 +++- .../view/ResourceExplorerTopComponent.java | 149 ++++++++---------- 2 files changed, 92 insertions(+), 87 deletions(-) diff --git a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/service/ImplementationManagerService.java b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/service/ImplementationManagerService.java index 030425f6254..b2ccfb87af4 100644 --- a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/service/ImplementationManagerService.java +++ b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/service/ImplementationManagerService.java @@ -1,3 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ package org.apache.syncope.ide.netbeans.service; import java.util.List; @@ -21,19 +39,19 @@ public List list(final ImplementationType type) { return service.list(type); } - public ImplementationTO read(final ImplementationType type ,final String key) { - return service.read(type,key); + public ImplementationTO read(final ImplementationType type , final String key) { + return service.read(type, key); } public boolean create(final ImplementationTO implementationTO) { return Response.Status.CREATED.getStatusCode() == service.create(implementationTO).getStatus(); } - public boolean delete(final ImplementationType type , String key) { - return Response.Status.NO_CONTENT.getStatusCode() == service.delete(type,key).getStatus(); + public boolean delete(final ImplementationType type , final String key) { + return Response.Status.NO_CONTENT.getStatusCode() == service.delete(type, key).getStatus(); } - public boolean update(final ImplementationTO implementationTO ) { + public boolean update(final ImplementationTO implementationTO) { return Response.Status.NO_CONTENT.getStatusCode() == service.update(implementationTO).getStatus(); } -} \ No newline at end of file +} diff --git a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java index 3d923bdc4b1..70cec1c106a 100644 --- a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java +++ b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java @@ -48,7 +48,6 @@ import org.apache.syncope.common.lib.to.MailTemplateTO; import org.apache.syncope.common.lib.to.ReportTemplateTO; import org.apache.syncope.common.lib.to.ImplementationTO; -import org.apache.syncope.common.lib.types.ClientExceptionType; import org.apache.syncope.common.lib.types.MailTemplateFormat; import org.apache.syncope.common.lib.types.ReportTemplateFormat; import org.apache.syncope.common.lib.types.ImplementationType; @@ -192,7 +191,7 @@ private void resourceExplorerTreeMouseClicked(final java.awt.event.MouseEvent ev } else if (PluginConstants.REPORT_XSLTS.equals(parentNodeName)) { openReportEditor(leafNodeName); } else if (PluginConstants.GROOVY_SCRIPTS.equals(grandParentNodeName)) { - openScriptEditor(leafNodeName,parentNodeName); + openScriptEditor(leafNodeName , parentNodeName); } } catch (IOException e) { Exceptions.printStackTrace(e); @@ -214,8 +213,8 @@ private void resourceExplorerTreeMouseClicked(final java.awt.event.MouseEvent ev folderRightClickAction(evt, mailTemplates); } else if (PluginConstants.REPORT_XSLTS.equals(selectedNodeName)) { folderRightClickAction(evt, reportXslts); - } else if(PluginConstants.GROOVY_SCRIPTS.equals(parentNodeName)){ - folderRightClickAction(evt,selectedNode); + } else if (PluginConstants.GROOVY_SCRIPTS.equals(parentNodeName)) { + folderRightClickAction(evt, selectedNode); } else if (PluginConstants.ROOT_NAME.equals(selectedNodeName)) { rootRightClickAction(evt); } @@ -272,22 +271,21 @@ public boolean cancel() { } catch (IOException e) { JOptionPane.showMessageDialog(null, e.getMessage(), "Generic Error", JOptionPane.ERROR_MESSAGE); ServerDetailsView serverDetails = getRefreshServerDetails(); - } - catch(Exception ex) { + } catch (Exception ex) { getRefreshServerDetails().setVisible(true); } - + } @Override public void componentClosed() { - // TODO add custom code on component - resetTree(); + // TODO add custom code on component + resetTree(); } void writeProperties(final java.util.Properties p) { // better to version settings since initial version as advocated at // http://wiki.apidesign.org/wiki/PropertyFiles - p.setProperty("version", "1.0"); + p.setProperty("version", "1.0"); // TODO store your settings } @@ -315,14 +313,15 @@ private void addReportXslts() { } private void addGroovyScripts() { - for(ImplementationType type : ImplementationType.values()) - { + for (ImplementationType type : ImplementationType.values()) { String implType = type.toString(); DefaultMutableTreeNode tempNode = new DefaultMutableTreeNode(implType.toString()); - if(implType.equals("JWT_SSO_PROVIDER") || implType.equals("AUDIT_APPENDER") ) continue ; + if (implType.equals("JWT_SSO_PROVIDER") || implType.equals("AUDIT_APPENDER")) { + continue ; + } List scripts = implementationManagerService.list(type); - for(ImplementationTO script : scripts) { - if(script.getEngine() == ImplementationEngine.GROOVY) { + for (ImplementationTO script : scripts) { + if (script.getEngine() == ImplementationEngine.GROOVY) { tempNode.add(new DefaultMutableTreeNode( script.getKey())); } @@ -332,7 +331,7 @@ private void addGroovyScripts() { treeModel.reload(); } - + private void rootRightClickAction(final MouseEvent evt) { JPopupMenu menu = new JPopupMenu(); JMenuItem refreshItem = new JMenuItem("Refresh Templates"); @@ -386,14 +385,15 @@ private void folderRightClickAction(final MouseEvent evt, public void actionPerformed(final ActionEvent e) { try { String name = "" ; - while(name.equals("")) + while (name.equals("")) { name = JOptionPane.showInputDialog("Enter Name"); + } DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); 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); @@ -403,10 +403,10 @@ public void actionPerformed(final ActionEvent e) { mailTemplateManagerService.setFormat(name, MailTemplateFormat.TEXT, IOUtils.toInputStream("//Enter Content here", encodingPattern)); - openMailEditor(name); - } else if((parent.getUserObject().equals(PluginConstants.GROOVY_SCRIPTS))) { + openMailEditor(name); + } else if ((parent.getUserObject().equals(PluginConstants.GROOVY_SCRIPTS))) { ImplementationTO newNode = new ImplementationTO(); - ImplementationType type = getType((String)node.getUserObject()); + ImplementationType type = getType((String) node.getUserObject()); newNode.setKey(name); newNode.setEngine(ImplementationEngine.GROOVY); newNode.setType(type); @@ -458,7 +458,7 @@ public void actionPerformed(final ActionEvent e) { case PUSH_CORRELATION_RULE: templateClassName = "MyPushCorrelationRule"; - break; + break; case VALIDATOR: templateClassName = "MyValidator"; @@ -475,7 +475,7 @@ public void actionPerformed(final ActionEvent e) { getClass().getResourceAsStream("/org/apache/syncope/ide/netbeans/implementations/" + templateClassName + ".groovy"))); added = implementationManagerService.create(newNode); - openScriptEditor(name,(String)node.getUserObject()); + openScriptEditor(name, (String) node.getUserObject()); } else { ReportTemplateTO reportTemplate = new ReportTemplateTO(); reportTemplate.setKey(name); @@ -500,13 +500,11 @@ public void actionPerformed(final ActionEvent e) { null, "Error while creating new element", "Error", JOptionPane.ERROR_MESSAGE); } } - }catch(SyncopeClientException excp) { + } catch (SyncopeClientException excp) { JOptionPane.showMessageDialog(null, excp.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); - } - catch(IOException | NullPointerException ex) { - JOptionPane.showMessageDialog(null ,ex.getMessage(),"Error", JOptionPane.ERROR_MESSAGE); - } - catch(Exception exc) { + } catch (IOException | NullPointerException ex) { + JOptionPane.showMessageDialog(null , ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); + } catch (Exception exc) { getRefreshServerDetails().setVisible(true); } } @@ -530,29 +528,26 @@ public void actionPerformed(final ActionEvent e) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); String nodeName = (String) node.getUserObject() ; boolean deleted = false; - boolean fileDeleted = false ; - String tempFilePath = "" ; try { if (parent.getUserObject().equals(PluginConstants.MAIL_TEMPLATES)) { deleted = mailTemplateManagerService.delete(nodeName); - } else if(parent.getUserObject().equals(PluginConstants.REPORT_XSLTS)) { + } else if (parent.getUserObject().equals(PluginConstants.REPORT_XSLTS)) { deleted = reportTemplateManagerService.delete(nodeName); } else { - ImplementationType type = getType((String)parent.getUserObject()); + ImplementationType type = getType((String) parent.getUserObject()); deleted = implementationManagerService.delete(type, nodeName); } - if(deleted) { + if (deleted) { node.removeFromParent(); treeModel.reload(parent); } else { JOptionPane.showMessageDialog( null, "Error while deleting new element", "Error", JOptionPane.ERROR_MESSAGE); } - } catch(SyncopeClientException exc) { + } catch (SyncopeClientException exc) { JOptionPane.showMessageDialog( null, exc.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); - } - catch (Exception ex) { + } catch (Exception ex) { getRefreshServerDetails().setVisible(true); } } @@ -586,7 +581,7 @@ private void openMailEditor(final String name) throws IOException { default: LOG.log(Level.SEVERE, String.format("Format [%s] not supported", format)); break; - } + } String content = is == null ? StringUtils.EMPTY : IOUtils.toString(is, encodingPattern); String mailTemplatesDirName = System.getProperty("java.io.tmpdir") + "/Templates/Mail/"; @@ -613,15 +608,13 @@ public void propertyChange(final PropertyChangeEvent evt) { } } }); - } catch (SyncopeClientException ex) { + } catch (SyncopeClientException ex) { JOptionPane.showMessageDialog( - null, ex.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); - } - catch(IOException | NullPointerException excp) { - JOptionPane.showMessageDialog(null ,excp.getMessage(), "Error" ,JOptionPane.ERROR_MESSAGE); - } - catch (Exception ex) { - LOG.info("The Exception is"+ ex); + null, ex.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); + } catch (IOException | NullPointerException excp) { + JOptionPane.showMessageDialog(null , excp.getMessage(), "Error" , JOptionPane.ERROR_MESSAGE); + } catch (Exception ex) { + LOG.info("The Exception is" + ex); getRefreshServerDetails().setVisible(true); } } @@ -629,13 +622,14 @@ public void propertyChange(final PropertyChangeEvent evt) { private void openScriptEditor(final String name , final String type) throws IOException { try { - ImplementationTO node = implementationManagerService.read(getType(type),name); - String groovyScriptsDirName = System.getProperty("java.io.tmpdir") + "/Groovy/" + node.getType().toString() + "/"; + ImplementationTO node = implementationManagerService.read(getType(type), name); + String groovyScriptsDirName = System.getProperty("java.io.tmpdir") + "/Groovy/" + + node.getType().toString() + "/"; File groovyScriptsDir = new File(groovyScriptsDirName); if (!groovyScriptsDir.exists()) { groovyScriptsDir.mkdirs(); } - File file = new File(groovyScriptsDirName + name + ".groovy" ); + File file = new File(groovyScriptsDirName + name + ".groovy"); FileWriter fw = new FileWriter(file); fw.write(node.getBody()); fw.flush(); @@ -653,18 +647,15 @@ public void propertyChange(final PropertyChangeEvent evt) { } } }); - + } catch (SyncopeClientException ex) { - JOptionPane.showMessageDialog( - null, ex.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); - } - catch(IOException | NullPointerException excp) { - JOptionPane.showMessageDialog(null ,excp.getMessage(), "Error" ,JOptionPane.ERROR_MESSAGE); - } - catch (Exception ex) { - LOG.info("The Exception is"+ ex); + JOptionPane.showMessageDialog(null, ex.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); + } catch (IOException | NullPointerException excp) { + JOptionPane.showMessageDialog(null , excp.getMessage(), "Error" , JOptionPane.ERROR_MESSAGE); + } catch (Exception ex) { + LOG.info("The Exception is" + ex); getRefreshServerDetails().setVisible(true); - } + } } private void openReportEditor(final String name) throws IOException { @@ -718,15 +709,13 @@ public void propertyChange(final PropertyChangeEvent evt) { }); } catch (SyncopeClientException ex) { JOptionPane.showMessageDialog( - null, ex.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); - } - catch(IOException | NullPointerException excp) { - JOptionPane.showMessageDialog(null ,excp.getMessage(), "Error" ,JOptionPane.ERROR_MESSAGE); - } - catch (Exception ex) { - LOG.info("The Exception is"+ ex); + null, ex.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); + } catch (IOException | NullPointerException excp) { + JOptionPane.showMessageDialog(null , excp.getMessage(), "Error" , JOptionPane.ERROR_MESSAGE); + } catch (Exception ex) { + LOG.info("The Exception is" + ex); getRefreshServerDetails().setVisible(true); - } + } } } @@ -736,7 +725,7 @@ private void saveContent() { Document document = ed.getDocument(); String content = document.getText(0, document.getLength()); String path = (String) document.getProperty(Document.TitleProperty); - String[] temp = path.split(File.separator.replace("\\","\\\\")); + String[] temp = path.split(File.separator.replace("\\", "\\\\")); String name = temp[temp.length - 1]; String fileName = temp[temp.length - 3]; String templateType = temp[temp.length - 2]; @@ -762,34 +751,32 @@ private void saveContent() { reportTemplateManagerService.setFormat(key, ReportTemplateFormat.FO, IOUtils.toInputStream(content, encodingPattern)); - } else if(format.equals("csv")) { + } else if (format.equals("csv")) { reportTemplateManagerService.setFormat(key, ReportTemplateFormat.CSV, IOUtils.toInputStream(content, encodingPattern)); - } - else if(fileName.equals("Groovy")) { + } else if (fileName.equals("Groovy")) { LOG.info("Setting groovy"); - ImplementationTO node = implementationManagerService.read(getType(templateType),key); + ImplementationTO node = implementationManagerService.read(getType(templateType), key); node.setBody(content); implementationManagerService.update(node); - } + } } catch (BadLocationException e) { Exceptions.printStackTrace(e); - } - catch (Exception e) { + } catch (Exception e) { getRefreshServerDetails().setVisible(true); } } - - private ImplementationType getType(String typeName){ + + private ImplementationType getType(final String typeName) { ImplementationType type = null ; - for(ImplementationType implType : ImplementationType.values()){ - if(implType.toString().equals(typeName)) { + for (ImplementationType implType : ImplementationType.values()) { + if (implType.toString().equals(typeName)) { type = implType ; } - + } - return(type); + return (type); } private void closeComponent() { From 50ff3e88a2fd674783b5def4c30172232fa716b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Tue, 14 Aug 2018 09:20:14 +0200 Subject: [PATCH 12/15] [SYNCOPE-1220] Support Groovy implementation in the Netbeans plugin --- ide/netbeans/pom.xml | 1 + .../syncope/ide/netbeans/PluginConstants.java | 2 + .../ide/netbeans/ResourceConnector.java | 16 + .../service/ImplementationManagerService.java | 57 ++++ .../view/ResourceExplorerTopComponent.java | 309 +++++++++++++----- .../implementations/MyAccountRule.groovy | 29 ++ .../implementations/MyItemTransformer.groovy | 46 +++ .../implementations/MyLogicActions.groovy | 38 +++ .../implementations/MyPasswordRule.groovy | 28 ++ .../MyPropagationActions.groovy | 43 +++ .../implementations/MyPullActions.groovy | 122 +++++++ .../MyPullCorrelationRule.groovy | 32 ++ .../implementations/MyPushActions.groovy | 112 +++++++ .../MyRecipientsProvider.groovy | 31 ++ .../MyReconFilterBuilder.groovy | 30 ++ .../implementations/MyReportlet.groovy | 30 ++ .../MySchedTaskJobDelegate.groovy | 31 ++ .../implementations/MyValidator.groovy | 34 ++ pom.xml | 6 +- 19 files changed, 914 insertions(+), 83 deletions(-) create mode 100644 ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/service/ImplementationManagerService.java create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyAccountRule.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyItemTransformer.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyLogicActions.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPasswordRule.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPropagationActions.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPullActions.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPullCorrelationRule.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPushActions.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyRecipientsProvider.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyReconFilterBuilder.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyReportlet.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MySchedTaskJobDelegate.groovy create mode 100644 ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyValidator.groovy diff --git a/ide/netbeans/pom.xml b/ide/netbeans/pom.xml index 0a2ef1248b9..0429889ea7c 100644 --- a/ide/netbeans/pom.xml +++ b/ide/netbeans/pom.xml @@ -176,6 +176,7 @@ under the License. false org/apache/syncope/**/*.png + org/apache/syncope/**/*.groovy diff --git a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/PluginConstants.java b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/PluginConstants.java index ea2fd80b7d2..c1359bf3098 100644 --- a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/PluginConstants.java +++ b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/PluginConstants.java @@ -27,6 +27,8 @@ public final class PluginConstants { public static final String REPORT_XSLTS = "Report XSLTs"; + public static final String GROOVY_SCRIPTS = "Groovy Scripts"; + public static final String[] MAIL_TEMPLATE_FORMATS = { MailTemplateFormat.HTML.name(), MailTemplateFormat.TEXT.name() }; diff --git a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/ResourceConnector.java b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/ResourceConnector.java index b7739fa9e79..51df938d05a 100644 --- a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/ResourceConnector.java +++ b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/ResourceConnector.java @@ -23,6 +23,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.syncope.ide.netbeans.service.MailTemplateManagerService; import org.apache.syncope.ide.netbeans.service.ReportTemplateManagerService; +import org.apache.syncope.ide.netbeans.service.ImplementationManagerService; import org.apache.syncope.ide.netbeans.view.ResourceExplorerTopComponent; import org.openide.util.NbPreferences; @@ -32,10 +33,14 @@ public final class ResourceConnector { private static ReportTemplateManagerService REPORT_TEMPLATE_MANAGER_SERVICE; + private static ImplementationManagerService IMPLEMENTATION_MANAGER_SERVICE; + private static final Object MAIL_TEMPLATE_MONITOR = new Object(); private static final Object REPORT_TEMPLATE_MONITOR = new Object(); + private static final Object IMPLEMENTATION_MONITOR = new Object(); + private ResourceConnector() { } @@ -61,6 +66,17 @@ public static ReportTemplateManagerService getReportTemplateManagerService() thr return REPORT_TEMPLATE_MANAGER_SERVICE; } + public static ImplementationManagerService getImplementationManagerService() throws IOException { + synchronized (IMPLEMENTATION_MONITOR) { + ConnectionParams connParams = getConnectionParams(); + IMPLEMENTATION_MANAGER_SERVICE = new ImplementationManagerService( + connParams.getUrl(), + connParams.getUsername(), + connParams.getPassword()); + } + return IMPLEMENTATION_MANAGER_SERVICE; + } + public static ConnectionParams getConnectionParams() { Preferences prefs = NbPreferences.forModule(ResourceExplorerTopComponent.class); return ConnectionParams.builder() diff --git a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/service/ImplementationManagerService.java b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/service/ImplementationManagerService.java new file mode 100644 index 00000000000..b2ccfb87af4 --- /dev/null +++ b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/service/ImplementationManagerService.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.syncope.ide.netbeans.service; + +import java.util.List; +import javax.ws.rs.core.Response; +import org.apache.syncope.client.lib.SyncopeClient; +import org.apache.syncope.client.lib.SyncopeClientFactoryBean; +import org.apache.syncope.common.lib.to.ImplementationTO; +import org.apache.syncope.common.lib.types.ImplementationType; +import org.apache.syncope.common.rest.api.service.ImplementationService; + +public class ImplementationManagerService { + + private final ImplementationService service ; + + public ImplementationManagerService(final String url, final String userName, final String password) { + SyncopeClient syncopeClient = new SyncopeClientFactoryBean().setAddress(url).create(userName, password); + service = syncopeClient.getService(ImplementationService.class); + } + + public List list(final ImplementationType type) { + return service.list(type); + } + + public ImplementationTO read(final ImplementationType type , final String key) { + return service.read(type, key); + } + + public boolean create(final ImplementationTO implementationTO) { + return Response.Status.CREATED.getStatusCode() == service.create(implementationTO).getStatus(); + } + + public boolean delete(final ImplementationType type , final String key) { + return Response.Status.NO_CONTENT.getStatusCode() == service.delete(type, key).getStatus(); + } + + public boolean update(final ImplementationTO implementationTO) { + return Response.Status.NO_CONTENT.getStatusCode() == service.update(implementationTO).getStatus(); + } +} diff --git a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java index b2a01984a35..70cec1c106a 100644 --- a/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java +++ b/ide/netbeans/src/main/java/org/apache/syncope/ide/netbeans/view/ResourceExplorerTopComponent.java @@ -47,13 +47,16 @@ import org.apache.syncope.common.lib.SyncopeClientException; import org.apache.syncope.common.lib.to.MailTemplateTO; import org.apache.syncope.common.lib.to.ReportTemplateTO; -import org.apache.syncope.common.lib.types.ClientExceptionType; +import org.apache.syncope.common.lib.to.ImplementationTO; import org.apache.syncope.common.lib.types.MailTemplateFormat; import org.apache.syncope.common.lib.types.ReportTemplateFormat; +import org.apache.syncope.common.lib.types.ImplementationType; +import org.apache.syncope.common.lib.types.ImplementationEngine; import org.apache.syncope.ide.netbeans.PluginConstants; import org.apache.syncope.ide.netbeans.ResourceConnector; import org.apache.syncope.ide.netbeans.service.MailTemplateManagerService; import org.apache.syncope.ide.netbeans.service.ReportTemplateManagerService; +import org.apache.syncope.ide.netbeans.service.ImplementationManagerService; import org.netbeans.api.editor.EditorRegistry; import org.netbeans.api.progress.ProgressHandle; import org.netbeans.api.settings.ConvertAsProperties; @@ -106,10 +109,14 @@ public final class ResourceExplorerTopComponent extends TopComponent { private final DefaultMutableTreeNode reportXslts; + private final DefaultMutableTreeNode groovyScripts; + private MailTemplateManagerService mailTemplateManagerService; private ReportTemplateManagerService reportTemplateManagerService; + private ImplementationManagerService implementationManagerService; + private Charset encodingPattern; public ResourceExplorerTopComponent() { @@ -123,6 +130,7 @@ public ResourceExplorerTopComponent() { visibleRoot = new DefaultMutableTreeNode(PluginConstants.ROOT_NAME); mailTemplates = new DefaultMutableTreeNode(PluginConstants.MAIL_TEMPLATES); reportXslts = new DefaultMutableTreeNode(PluginConstants.REPORT_XSLTS); + groovyScripts = new DefaultMutableTreeNode(PluginConstants.GROOVY_SCRIPTS); root.add(visibleRoot); initTemplatesTree(); } @@ -175,29 +183,38 @@ private void resourceExplorerTreeMouseClicked(final java.awt.event.MouseEvent ev String parentNodeName = parentNode == null ? null : String.valueOf(parentNode.getUserObject()); if (selectedNode.isLeaf() && StringUtils.isNotBlank(parentNodeName)) { String leafNodeName = (String) selectedNode.getUserObject(); + DefaultMutableTreeNode grandParentNode = (DefaultMutableTreeNode) parentNode.getParent(); + String grandParentNodeName = (String) grandParentNode.getUserObject(); try { if (PluginConstants.MAIL_TEMPLATES.equals(parentNodeName)) { openMailEditor(leafNodeName); } else if (PluginConstants.REPORT_XSLTS.equals(parentNodeName)) { openReportEditor(leafNodeName); + } else if (PluginConstants.GROOVY_SCRIPTS.equals(grandParentNodeName)) { + openScriptEditor(leafNodeName , parentNodeName); } } catch (IOException e) { Exceptions.printStackTrace(e); - } + } } } else if (evt.getButton() == MouseEvent.BUTTON3 && evt.getClickCount() == 1) { DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) resourceExplorerTree. getLastSelectedPathComponent(); + DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selectedNode.getParent(); + String parentNodeName = (String) parent.getUserObject(); String selectedNodeName = (String) selectedNode.getUserObject(); if (selectedNode.isLeaf() && !PluginConstants.ROOT_NAME.equals(selectedNodeName) && !PluginConstants.MAIL_TEMPLATES.equals(selectedNodeName) - && !PluginConstants.REPORT_XSLTS.equals(selectedNodeName)) { + && !PluginConstants.REPORT_XSLTS.equals(selectedNodeName) + && !PluginConstants.GROOVY_SCRIPTS.equals(parentNodeName)) { leafRightClickAction(evt, selectedNode); } else if (PluginConstants.MAIL_TEMPLATES.equals(selectedNodeName)) { folderRightClickAction(evt, mailTemplates); } else if (PluginConstants.REPORT_XSLTS.equals(selectedNodeName)) { folderRightClickAction(evt, reportXslts); + } else if (PluginConstants.GROOVY_SCRIPTS.equals(parentNodeName)) { + folderRightClickAction(evt, selectedNode); } else if (PluginConstants.ROOT_NAME.equals(selectedNodeName)) { rootRightClickAction(evt); } @@ -223,6 +240,7 @@ public void componentOpened() { try { mailTemplateManagerService = ResourceConnector.getMailTemplateManagerService(); reportTemplateManagerService = ResourceConnector.getReportTemplateManagerService(); + implementationManagerService = ResourceConnector.getImplementationManagerService(); // init tree, because on close it is reset initTemplatesTree(); // Load templates @@ -244,42 +262,24 @@ public boolean cancel() { progr.progress("Loading Templates."); addMailTemplates(); addReportXslts(); + addGroovyScripts(); progr.finish(); } - }; + }; REQUEST_PROCESSOR.post(tsk); - } catch (Exception e) { + } catch (IOException e) { JOptionPane.showMessageDialog(null, e.getMessage(), "Generic Error", JOptionPane.ERROR_MESSAGE); ServerDetailsView serverDetails = getRefreshServerDetails(); + } catch (Exception ex) { + getRefreshServerDetails().setVisible(true); } - Runnable tsk = new Runnable() { - - @Override - public void run() { - final ProgressHandle progr = ProgressHandle.createHandle("Loading Templates", new Cancellable() { - - @Override - public boolean cancel() { - return true; - } - }); - - progr.start(); - progr.progress("Loading Templates."); - addMailTemplates(); - addReportXslts(); - progr.finish(); - } - - }; - RequestProcessor.getDefault().post(tsk); } - @Override public void componentClosed() { - // TODO add custom code on component closing + // TODO add custom code on component + resetTree(); } void writeProperties(final java.util.Properties p) { @@ -312,6 +312,26 @@ private void addReportXslts() { treeModel.reload(); } + private void addGroovyScripts() { + for (ImplementationType type : ImplementationType.values()) { + String implType = type.toString(); + DefaultMutableTreeNode tempNode = new DefaultMutableTreeNode(implType.toString()); + if (implType.equals("JWT_SSO_PROVIDER") || implType.equals("AUDIT_APPENDER")) { + continue ; + } + List scripts = implementationManagerService.list(type); + for (ImplementationTO script : scripts) { + if (script.getEngine() == ImplementationEngine.GROOVY) { + tempNode.add(new DefaultMutableTreeNode( + script.getKey())); + } + } + groovyScripts.add(tempNode); + } + + treeModel.reload(); + } + private void rootRightClickAction(final MouseEvent evt) { JPopupMenu menu = new JPopupMenu(); JMenuItem refreshItem = new JMenuItem("Refresh Templates"); @@ -363,11 +383,17 @@ private void folderRightClickAction(final MouseEvent evt, @Override public void actionPerformed(final ActionEvent e) { - String name = JOptionPane.showInputDialog("Enter Name"); + try { + String name = "" ; + while (name.equals("")) { + name = JOptionPane.showInputDialog("Enter Name"); + } + DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); 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); @@ -377,11 +403,79 @@ public void actionPerformed(final ActionEvent e) { mailTemplateManagerService.setFormat(name, MailTemplateFormat.TEXT, IOUtils.toInputStream("//Enter Content here", encodingPattern)); - try { openMailEditor(name); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } + } else if ((parent.getUserObject().equals(PluginConstants.GROOVY_SCRIPTS))) { + ImplementationTO newNode = new ImplementationTO(); + ImplementationType type = getType((String) node.getUserObject()); + newNode.setKey(name); + newNode.setEngine(ImplementationEngine.GROOVY); + newNode.setType(type); + String templateClassName = null; + switch (type) { + case REPORTLET: + templateClassName = "MyReportlet"; + break; + + case ACCOUNT_RULE: + templateClassName = "MyAccountRule"; + break; + + case PASSWORD_RULE: + templateClassName = "MyPasswordRule"; + break; + + case ITEM_TRANSFORMER: + templateClassName = "MyItemTransformer"; + break; + + case TASKJOB_DELEGATE: + templateClassName = "MySchedTaskJobDelegate"; + break; + + case RECON_FILTER_BUILDER: + templateClassName = "MyReconFilterBuilder"; + break; + + case LOGIC_ACTIONS: + templateClassName = "MyLogicActions"; + break; + + case PROPAGATION_ACTIONS: + templateClassName = "MyPropagationActions"; + break; + + case PULL_ACTIONS: + templateClassName = "MyPullActions"; + break; + + case PUSH_ACTIONS: + templateClassName = "MyPushActions"; + break; + + case PULL_CORRELATION_RULE: + templateClassName = "MyPullCorrelationRule"; + break; + + case PUSH_CORRELATION_RULE: + templateClassName = "MyPushCorrelationRule"; + break; + + case VALIDATOR: + templateClassName = "MyValidator"; + break; + + case RECIPIENTS_PROVIDER: + templateClassName = "MyRecipientsProvider"; + break; + + default: + } + LOG.info(templateClassName); + newNode.setBody(IOUtils.toString( + getClass().getResourceAsStream("/org/apache/syncope/ide/netbeans/implementations/" + + templateClassName + ".groovy"))); + added = implementationManagerService.create(newNode); + openScriptEditor(name, (String) node.getUserObject()); } else { ReportTemplateTO reportTemplate = new ReportTemplateTO(); reportTemplate.setKey(name); @@ -395,11 +489,7 @@ public void actionPerformed(final ActionEvent e) { reportTemplateManagerService.setFormat(name, ReportTemplateFormat.HTML, IOUtils.toInputStream("//Enter content here", encodingPattern)); - try { openReportEditor(name); - } catch (IOException ex) { - Exceptions.printStackTrace(ex); - } } if (added) { @@ -410,7 +500,14 @@ public void actionPerformed(final ActionEvent e) { null, "Error while creating new element", "Error", JOptionPane.ERROR_MESSAGE); } } + } catch (SyncopeClientException excp) { + JOptionPane.showMessageDialog(null, excp.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); + } catch (IOException | NullPointerException ex) { + JOptionPane.showMessageDialog(null , ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); + } catch (Exception exc) { + getRefreshServerDetails().setVisible(true); } + } }); menu.show(evt.getComponent(), evt.getX(), evt.getY()); @@ -429,11 +526,16 @@ public void actionPerformed(final ActionEvent e) { int result = JOptionPane.showConfirmDialog(null, "Are you sure to delete the item?"); if (result == JOptionPane.OK_OPTION) { DefaultMutableTreeNode parent = (DefaultMutableTreeNode) node.getParent(); - boolean deleted; + String nodeName = (String) node.getUserObject() ; + boolean deleted = false; + try { if (parent.getUserObject().equals(PluginConstants.MAIL_TEMPLATES)) { - deleted = mailTemplateManagerService.delete((String) node.getUserObject()); + deleted = mailTemplateManagerService.delete(nodeName); + } else if (parent.getUserObject().equals(PluginConstants.REPORT_XSLTS)) { + deleted = reportTemplateManagerService.delete(nodeName); } else { - deleted = reportTemplateManagerService.delete((String) node.getUserObject()); + ImplementationType type = getType((String) parent.getUserObject()); + deleted = implementationManagerService.delete(type, nodeName); } if (deleted) { node.removeFromParent(); @@ -442,6 +544,12 @@ public void actionPerformed(final ActionEvent e) { JOptionPane.showMessageDialog( null, "Error while deleting new element", "Error", JOptionPane.ERROR_MESSAGE); } + } catch (SyncopeClientException exc) { + JOptionPane.showMessageDialog( + null, exc.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); + } catch (Exception ex) { + getRefreshServerDetails().setVisible(true); + } } } }); @@ -460,7 +568,7 @@ private void openMailEditor(final String name) throws IOException { String type = null; InputStream is = null; - try { + try { switch (format) { case HTML: type = "html"; @@ -474,24 +582,6 @@ private void openMailEditor(final String name) throws IOException { LOG.log(Level.SEVERE, String.format("Format [%s] not supported", format)); break; } - } catch (SyncopeClientException e) { - LOG.log(Level.SEVERE, - String.format("Unable to get [%s] mail template in [%s] format", name, format), e); - if (ClientExceptionType.NotFound.equals(e.getType())) { - LOG.log(Level.SEVERE, String.format( - "Report template in [%s] format not found, create an empty one", format)); - } else { - JOptionPane.showMessageDialog( - null, String.format("Unable to get [%s] report template in [%s] format", name, format), - "Connection Error", JOptionPane.ERROR_MESSAGE); - } - } catch (Exception e) { - LOG.log(Level.SEVERE, - String.format("Unable to get [%s] mail template in [%s] format", name, format), e); - JOptionPane.showMessageDialog( - null, String.format("Unable to get [%s] mail template in [%s] format", name, format), "Error", - JOptionPane.ERROR_MESSAGE); - } String content = is == null ? StringUtils.EMPTY : IOUtils.toString(is, encodingPattern); String mailTemplatesDirName = System.getProperty("java.io.tmpdir") + "/Templates/Mail/"; @@ -518,6 +608,53 @@ public void propertyChange(final PropertyChangeEvent evt) { } } }); + } catch (SyncopeClientException ex) { + JOptionPane.showMessageDialog( + null, ex.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); + } catch (IOException | NullPointerException excp) { + JOptionPane.showMessageDialog(null , excp.getMessage(), "Error" , JOptionPane.ERROR_MESSAGE); + } catch (Exception ex) { + LOG.info("The Exception is" + ex); + getRefreshServerDetails().setVisible(true); + } + } + } + + private void openScriptEditor(final String name , final String type) throws IOException { + try { + ImplementationTO node = implementationManagerService.read(getType(type), name); + String groovyScriptsDirName = System.getProperty("java.io.tmpdir") + "/Groovy/" + + node.getType().toString() + "/"; + File groovyScriptsDir = new File(groovyScriptsDirName); + if (!groovyScriptsDir.exists()) { + groovyScriptsDir.mkdirs(); + } + File file = new File(groovyScriptsDirName + name + ".groovy"); + FileWriter fw = new FileWriter(file); + fw.write(node.getBody()); + fw.flush(); + FileObject fob = FileUtil.toFileObject(file.getAbsoluteFile()); + DataObject data = DataObject.find(fob); + data.getLookup().lookup(OpenCookie.class).open(); + data.addPropertyChangeListener(new PropertyChangeListener() { + + @Override + public void propertyChange(final PropertyChangeEvent evt) { + if (DataObject.PROP_MODIFIED.equals(evt.getPropertyName())) { + //save item remotely + LOG.info(String.format("Saving Groovy template [%s]", name)); + saveContent(); + } + } + }); + + } catch (SyncopeClientException ex) { + JOptionPane.showMessageDialog(null, ex.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); + } catch (IOException | NullPointerException excp) { + JOptionPane.showMessageDialog(null , excp.getMessage(), "Error" , JOptionPane.ERROR_MESSAGE); + } catch (Exception ex) { + LOG.info("The Exception is" + ex); + getRefreshServerDetails().setVisible(true); } } @@ -529,7 +666,7 @@ private void openReportEditor(final String name) throws IOException { ReportTemplateFormat format = ReportTemplateFormat.valueOf(formatStr); InputStream is = null; - try { + try { switch (format) { case HTML: is = (InputStream) reportTemplateManagerService.getFormat(name, ReportTemplateFormat.HTML); @@ -544,24 +681,6 @@ private void openReportEditor(final String name) throws IOException { LOG.log(Level.SEVERE, String.format("Format [%s] not supported", format)); break; } - } catch (SyncopeClientException e) { - LOG.log(Level.SEVERE, String.format("Unable to get [%s] report template in [%s] format", name, format), - e); - if (ClientExceptionType.NotFound.equals(e.getType())) { - LOG.log(Level.SEVERE, String.format( - "Report template [%s] not found, create an empty one", name)); - } else { - JOptionPane.showMessageDialog( - null, String.format("Unable to get [%s] report template in [%s] format", name, format), - "Connection Error", JOptionPane.ERROR_MESSAGE); - } - } catch (Exception e) { - LOG.log(Level.SEVERE, String.format("Unable to get [%s] report template in [%s] format", name, format), - e); - JOptionPane.showMessageDialog( - null, String.format("Unable to get [%s] report template in [%s] format", name, format), - "Generic Error", JOptionPane.ERROR_MESSAGE); - } String content = is == null ? StringUtils.EMPTY : IOUtils.toString(is, encodingPattern); String reportTemplatesDirName = System.getProperty("java.io.tmpdir") + "/Templates/Report/"; @@ -588,6 +707,15 @@ public void propertyChange(final PropertyChangeEvent evt) { } } }); + } catch (SyncopeClientException ex) { + JOptionPane.showMessageDialog( + null, ex.getMessage(), "Syncope Error", JOptionPane.ERROR_MESSAGE); + } catch (IOException | NullPointerException excp) { + JOptionPane.showMessageDialog(null , excp.getMessage(), "Error" , JOptionPane.ERROR_MESSAGE); + } catch (Exception ex) { + LOG.info("The Exception is" + ex); + getRefreshServerDetails().setVisible(true); + } } } @@ -597,8 +725,9 @@ private void saveContent() { Document document = ed.getDocument(); String content = document.getText(0, document.getLength()); String path = (String) document.getProperty(Document.TitleProperty); - String[] temp = path.split(File.separator); + String[] temp = path.split(File.separator.replace("\\", "\\\\")); String name = temp[temp.length - 1]; + String fileName = temp[temp.length - 3]; String templateType = temp[temp.length - 2]; temp = name.split("\\."); String format = temp[1]; @@ -622,14 +751,32 @@ private void saveContent() { reportTemplateManagerService.setFormat(key, ReportTemplateFormat.FO, IOUtils.toInputStream(content, encodingPattern)); - } else { + } else if (format.equals("csv")) { reportTemplateManagerService.setFormat(key, ReportTemplateFormat.CSV, IOUtils.toInputStream(content, encodingPattern)); + } else if (fileName.equals("Groovy")) { + LOG.info("Setting groovy"); + ImplementationTO node = implementationManagerService.read(getType(templateType), key); + node.setBody(content); + implementationManagerService.update(node); } } catch (BadLocationException e) { Exceptions.printStackTrace(e); + } catch (Exception e) { + getRefreshServerDetails().setVisible(true); + } + } + + private ImplementationType getType(final String typeName) { + ImplementationType type = null ; + for (ImplementationType implType : ImplementationType.values()) { + if (implType.toString().equals(typeName)) { + type = implType ; + } + } + return (type); } private void closeComponent() { @@ -642,6 +789,7 @@ private void closeComponent() { private void initTemplatesTree() { visibleRoot.add(mailTemplates); visibleRoot.add(reportXslts); + visibleRoot.add(groovyScripts); treeModel.reload(); } @@ -649,6 +797,7 @@ private void resetTree() { visibleRoot.removeAllChildren(); mailTemplates.removeAllChildren(); reportXslts.removeAllChildren(); + groovyScripts.removeAllChildren(); treeModel.reload(); } diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyAccountRule.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyAccountRule.groovy new file mode 100644 index 00000000000..978e76db1e8 --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyAccountRule.groovy @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.persistence.api.dao.AccountRule +import org.apache.syncope.core.persistence.api.entity.user.User + +@CompileStatic +class MyAccountRule implements AccountRule { + + void enforce(User user) { + } + +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyItemTransformer.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyItemTransformer.groovy new file mode 100644 index 00000000000..fd4b5d41cc2 --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyItemTransformer.groovy @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.common.lib.to.EntityTO +import org.apache.syncope.core.persistence.api.entity.Entity +import org.apache.syncope.core.persistence.api.entity.PlainAttrValue +import org.apache.syncope.core.persistence.api.entity.resource.Item +import org.apache.syncope.core.provisioning.api.data.ItemTransformer + +@CompileStatic +class MyItemTransformer implements ItemTransformer { + + @Override + List beforePropagation( + Item item, + Entity entity, + List values) { + + return values; + } + + @Override + List beforePull( + Item item, + EntityTO entityTO, + List values) { + + return values; + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyLogicActions.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyLogicActions.groovy new file mode 100644 index 00000000000..df22aa231bf --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyLogicActions.groovy @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.common.lib.patch.AnyPatch +import org.apache.syncope.common.lib.patch.AttrPatch +import org.apache.syncope.common.lib.to.AnyTO +import org.apache.syncope.common.lib.to.AttrTO +import org.apache.syncope.core.provisioning.api.LogicActions + +@CompileStatic +class MyLogicActions implements LogicActions { + + @Override + A beforeCreate(final A input) { + return input; + } + + @Override + M beforeUpdate(final M input) { + return input; + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPasswordRule.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPasswordRule.groovy new file mode 100644 index 00000000000..dab38baca8a --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPasswordRule.groovy @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.persistence.api.dao.PasswordRule +import org.apache.syncope.core.persistence.api.entity.user.User + +@CompileStatic +class MyPasswordRule implements PasswordRule { + + void enforce(User user) { + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPropagationActions.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPropagationActions.groovy new file mode 100644 index 00000000000..6a24777af2e --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPropagationActions.groovy @@ -0,0 +1,43 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.persistence.api.entity.task.PropagationTask +import org.apache.syncope.core.persistence.api.entity.task.TaskExec +import org.apache.syncope.core.provisioning.api.propagation.PropagationActions +import org.identityconnectors.framework.common.objects.ConnectorObject + +@CompileStatic +class MyPropagationActions implements PropagationActions { + + @Override + void before(PropagationTask task, ConnectorObject beforeObj) { + // do nothing + } + + @Override + void onError(PropagationTask task, TaskExec execution, Exception error) { + // do nothing + } + + @Override + void after(PropagationTask task, TaskExec execution, ConnectorObject afterObj) { + // do nothing + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPullActions.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPullActions.groovy new file mode 100644 index 00000000000..893e7a97f89 --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPullActions.groovy @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.common.lib.patch.AnyPatch +import org.apache.syncope.common.lib.to.EntityTO +import org.apache.syncope.core.persistence.api.entity.task.ProvisioningTask +import org.apache.syncope.core.provisioning.api.pushpull.IgnoreProvisionException +import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningActions +import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningProfile +import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport +import org.apache.syncope.core.provisioning.api.pushpull.PullActions +import org.identityconnectors.framework.common.objects.SyncDelta +import org.quartz.JobExecutionException + +@CompileStatic +class MyPullActions implements PullActions { + + @Override + SyncDelta preprocess(SyncDelta delta) { + return delta; + } + + @Override + void beforeProvision( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity) throws JobExecutionException { + + } + + @Override + void beforeAssign( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity) throws JobExecutionException { + + } + + @Override + void beforeUnassign( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity) throws JobExecutionException { + + } + + @Override + void beforeDeprovision( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity) throws JobExecutionException { + + } + + @Override + void beforeUnlink( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity) throws JobExecutionException { + + } + + @Override + void beforeLink( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity) throws JobExecutionException { + + } + + @Override +

void beforeUpdate( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity, + P anyPatch) throws JobExecutionException { + + } + + @Override + void beforeDelete( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity) throws JobExecutionException { + + } + + @Override + void after( + ProvisioningProfile profile, + SyncDelta delta, + EntityTO entity, + ProvisioningReport result) throws JobExecutionException { + + // do nothing + } + + @Override + IgnoreProvisionException onError( + ProvisioningProfile profile, + SyncDelta delta, + Exception e) throws JobExecutionException { + + return null; + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPullCorrelationRule.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPullCorrelationRule.groovy new file mode 100644 index 00000000000..bb56ebe04e7 --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPullCorrelationRule.groovy @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.persistence.api.dao.PullCorrelationRule +import org.apache.syncope.core.persistence.api.dao.search.SearchCond +import org.apache.syncope.core.persistence.api.entity.resource.Provision +import org.identityconnectors.framework.common.objects.ConnectorObject + +@CompileStatic +class MyPullCorrelationRule implements PullCorrelationRule { + + @Override + SearchCond getSearchCond(ConnectorObject connObj, Provision provision) { + + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPushActions.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPushActions.groovy new file mode 100644 index 00000000000..dad420636fd --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyPushActions.groovy @@ -0,0 +1,112 @@ + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.persistence.api.entity.Entity +import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningProfile +import org.apache.syncope.core.provisioning.api.pushpull.ProvisioningReport +import org.apache.syncope.core.provisioning.api.pushpull.PushActions +import org.quartz.JobExecutionException + +@CompileStatic +class MyPushActions implements PushActions { + + @Override + Entity beforeAssign( + ProvisioningProfile profile, + Entity entity) throws JobExecutionException { + + return entity; + } + + @Override + Entity beforeProvision( + ProvisioningProfile profile, + Entity entity) throws JobExecutionException { + + return entity; + } + + @Override + Entity beforeUpdate( + ProvisioningProfile profile, + Entity entity) throws JobExecutionException { + + return entity; + } + + @Override + Entity beforeLink( + ProvisioningProfile profile, + Entity entity) throws JobExecutionException { + + return entity; + } + + @Override + Entity beforeUnlink( + ProvisioningProfile profile, + Entity entity) throws JobExecutionException { + + return entity; + } + + @Override + Entity beforeUnassign( + ProvisioningProfile profile, + Entity entity) throws JobExecutionException { + + return entity; + } + + @Override + Entity beforeDeprovision( + ProvisioningProfile profile, + Entity entity) throws JobExecutionException { + + return entity; + } + + @Override + Entity beforeDelete( + ProvisioningProfile profile, + Entity entity) throws JobExecutionException { + + return entity; + } + + @Override + void onError( + ProvisioningProfile profile, + Entity entity, + ProvisioningReport result, + Exception error) throws JobExecutionException { + + // do nothing + } + + @Override + void after( + ProvisioningProfile profile, + Entity entity, + ProvisioningReport result) throws JobExecutionException { + + // do nothing + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyRecipientsProvider.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyRecipientsProvider.groovy new file mode 100644 index 00000000000..d118861800c --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyRecipientsProvider.groovy @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.persistence.api.attrvalue.validation.Validator +import org.apache.syncope.core.persistence.api.entity.Notification +import org.apache.syncope.core.provisioning.api.notification.RecipientsProvider + +@CompileStatic +class MyRecipientsProvider implements RecipientsProvider { + + @Override + Set provideRecipients(Notification notification) { + return Collections.emptyList(); + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyReconFilterBuilder.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyReconFilterBuilder.groovy new file mode 100644 index 00000000000..b19b88e66aa --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyReconFilterBuilder.groovy @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.provisioning.api.pushpull.ReconFilterBuilder +import org.identityconnectors.framework.common.objects.filter.Filter + +@CompileStatic +class MyReconFilterBuilder implements ReconFilterBuilder { + + @Override + Filter build() { + return PASS_THROUGH; + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyReportlet.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyReportlet.groovy new file mode 100644 index 00000000000..07447c21cb6 --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyReportlet.groovy @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.persistence.api.attrvalue.validation.Validator +import org.apache.syncope.core.persistence.api.dao.Reportlet +import org.xml.sax.SAXException + +@CompileStatic +class MyReportlet implements Reportlet { + + @Override + void extract(ContentHandler handler) throws SAXException { + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MySchedTaskJobDelegate.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MySchedTaskJobDelegate.groovy new file mode 100644 index 00000000000..3356319b044 --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MySchedTaskJobDelegate.groovy @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.provisioning.api.job.SchedTaskJobDelegate +import org.quartz.JobExecutionContext +import org.quartz.JobExecutionException + +@CompileStatic +class MySchedTaskJobDelegate implements SchedTaskJobDelegate { + + @Override + void execute(String taskKey, boolean dryRun, JobExecutionContext context) throws JobExecutionException { + + } +} diff --git a/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyValidator.groovy b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyValidator.groovy new file mode 100644 index 00000000000..b0c3e377501 --- /dev/null +++ b/ide/netbeans/src/main/resources/org/apache/syncope/ide/netbeans/implementations/MyValidator.groovy @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import groovy.transform.CompileStatic +import org.apache.syncope.core.persistence.api.attrvalue.validation.Validator +import org.apache.syncope.core.persistence.api.entity.PlainAttrValue +import org.apache.syncope.core.persistence.api.entity.PlainSchema + +@CompileStatic +class MyValidator implements Validator { + + @Override + void setSchema(PlainSchema schema) { + } + + @Override + void validate(String value, PlainAttrValue attrValue) { + } +} diff --git a/pom.xml b/pom.xml index 5aa6d05e62a..198b29f8d2b 100644 --- a/pom.xml +++ b/pom.xml @@ -433,7 +433,7 @@ under the License. 1.4.197 - 5.3.0-M1 + 5.3.0-RC1 ${project.build.directory}/test-classes ${project.build.directory}/bundles @@ -1910,7 +1910,7 @@ under the License. org.junit.platform junit-platform-surefire-provider - 1.3.0-M1 + 1.3.0-RC1 @@ -1928,7 +1928,7 @@ under the License. org.junit.platform junit-platform-surefire-provider - 1.3.0-M1 + 1.3.0-RC1 From a39dcc750f772fb9105a5d696e742cb24b289985 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Tue, 14 Aug 2018 14:02:04 +0200 Subject: [PATCH 13/15] [SYNCOPE-1348] Async test improvement --- .../apache/syncope/fit/core/BatchITCase.java | 36 ++++++++++--------- .../reference-guide/concepts/policies.adoc | 1 - 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/BatchITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/BatchITCase.java index 25980ed0932..ac8a0011203 100644 --- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/BatchITCase.java +++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/BatchITCase.java @@ -237,16 +237,18 @@ public void webClientAsync() throws IOException, JAXBException { URI monitor = response.getLocation(); assertNotNull(monitor); - // wait a bit... - try { - Thread.sleep(5000); - } catch (InterruptedException e) { + for (int i = 0; i < 10 && response.getStatus() == Response.Status.ACCEPTED.getStatusCode(); i++) { + // wait a bit... + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + } + + // check results + response = WebClient.create(monitor). + header(HttpHeaders.AUTHORIZATION, "Bearer " + adminClient.getJWT()). + type(RESTHeaders.multipartMixedWith(boundary.substring(2))).get(); } - - // check results: now available - response = WebClient.create(monitor). - header(HttpHeaders.AUTHORIZATION, "Bearer " + adminClient.getJWT()). - type(RESTHeaders.multipartMixedWith(boundary.substring(2))).get(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); assertTrue(response.getMediaType().toString(). startsWith(RESTHeaders.multipartMixedWith(boundary.substring(2)))); @@ -325,14 +327,16 @@ public void syncopeClientAsync() throws IOException, JAXBException { assertEquals(Response.Status.ACCEPTED.getStatusCode(), response.getStatus()); assertTrue(response.getMediaType().toString().startsWith(RESTHeaders.MULTIPART_MIXED)); - // wait a bit... - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - } + for (int i = 0; i < 10 && response.getStatus() == Response.Status.ACCEPTED.getStatusCode(); i++) { + // wait a bit... + try { + Thread.sleep(2000); + } catch (InterruptedException e) { + } - // check results: now available - response = batchResponse.poll(); + // check results + response = batchResponse.poll(); + } assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); assertTrue(response.getMediaType().toString().startsWith(RESTHeaders.MULTIPART_MIXED)); diff --git a/src/main/asciidoc/reference-guide/concepts/policies.adoc b/src/main/asciidoc/reference-guide/concepts/policies.adoc index a6b612d58fb..dbc3a581d83 100644 --- a/src/main/asciidoc/reference-guide/concepts/policies.adoc +++ b/src/main/asciidoc/reference-guide/concepts/policies.adoc @@ -305,7 +305,6 @@ with existing Users, Groups or Any Objects. The ifeval::["{snapshotOrRelease}" == "release"] https://github.com/apache/syncope/blob/syncope-{docVersion}/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/DefaultPullCorrelationRule.java[default^] -] endif::[] ifeval::["{snapshotOrRelease}" == "snapshot"] https://github.com/apache/syncope/blob/2_1_X/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/DefaultPullCorrelationRule.java[default^] From 6bd3a7e0e410fb590c3b4bc38e3e5bdca5bafc2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Tue, 14 Aug 2018 14:10:25 +0200 Subject: [PATCH 14/15] [SYNCOPE-1348] Remove duplicated 'any more' --- .../workingwithapachesyncope/restfulservices.adoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/asciidoc/reference-guide/workingwithapachesyncope/restfulservices.adoc b/src/main/asciidoc/reference-guide/workingwithapachesyncope/restfulservices.adoc index c5c18865988..2b6ce6b478a 100644 --- a/src/main/asciidoc/reference-guide/workingwithapachesyncope/restfulservices.adoc +++ b/src/main/asciidoc/reference-guide/workingwithapachesyncope/restfulservices.adoc @@ -375,7 +375,7 @@ Core will return an empty response, with status `202 Accepted`. Clients can poll the `/batch` endpoint in `GET` by passing the same boundary used for request: if `202 Accepted` is returned, then the request is still under processing; otherwise, `200 OK` will be returned, along with the full batch response. + -Once retrieved, the batch response is not available any more from the `/batch` endpoint any more. +Once retrieved, the batch response is not available any more from the `/batch` endpoint. ==== Search From 1fdde8c86b019b41fbd60ff5b430ecc4d23000af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Francesco=20Chicchiricc=C3=B2?= Date: Tue, 14 Aug 2018 18:04:42 +0200 Subject: [PATCH 15/15] Some Java 8 usage improvements --- .../syncope/core/logic/ResourceLogic.java | 16 +++++------ .../provisioning/java/MappingManagerImpl.java | 4 +-- .../provisioning/java/VirAttrHandlerImpl.java | 2 +- .../java/data/AbstractAnyDataBinder.java | 27 +++++++++---------- .../job/report/ReconciliationReportlet.java | 2 +- .../AbstractPropagationTaskExecutor.java | 2 +- .../provisioning/java/pushpull/PullUtils.java | 2 +- .../provisioning/java/pushpull/PushUtils.java | 2 +- .../provisioning/java/utils/MappingUtils.java | 8 +++--- 9 files changed, 31 insertions(+), 34 deletions(-) diff --git a/core/logic/src/main/java/org/apache/syncope/core/logic/ResourceLogic.java b/core/logic/src/main/java/org/apache/syncope/core/logic/ResourceLogic.java index bea59dbd8f8..4d6a4c29073 100644 --- a/core/logic/src/main/java/org/apache/syncope/core/logic/ResourceLogic.java +++ b/core/logic/src/main/java/org/apache/syncope/core/logic/ResourceLogic.java @@ -312,12 +312,12 @@ public ConnObjectTO readConnObject(final String key, final String anyTypeKey, fi } // 2. build connObjectKeyItem - Optional connObjectKeyItem = MappingUtils.getConnObjectKeyItem(init.getRight()); - if (!connObjectKeyItem.isPresent()) { - throw new NotFoundException( - "ConnObjectKey mapping for " + init.getMiddle() + " " + anyKey + " on resource '" + key + "'"); - } - Optional connObjectKeyValue = mappingManager.getConnObjectKeyValue(any, init.getRight()); + MappingItem connObjectKeyItem = MappingUtils.getConnObjectKeyItem(init.getRight()). + orElseThrow(() -> new NotFoundException( + "ConnObjectKey mapping for " + init.getMiddle() + " " + anyKey + " on resource '" + key + "'")); + String connObjectKeyValue = mappingManager.getConnObjectKeyValue(any, init.getRight()). + orElseThrow(() -> new NotFoundException( + "ConnObjectKey value for " + init.getMiddle() + " " + anyKey + " on resource '" + key + "'")); // 3. determine attributes to query Set linkinMappingItems = virSchemaDAO.findByProvision(init.getRight()).stream(). @@ -330,12 +330,12 @@ public ConnObjectTO readConnObject(final String key, final String anyTypeKey, fi Connector connector = connFactory.getConnector(init.getLeft()); ConnectorObject connectorObject = connector.getObject( init.getRight().getObjectClass(), - AttributeBuilder.build(connObjectKeyItem.get().getExtAttrName(), connObjectKeyValue.get()), + AttributeBuilder.build(connObjectKeyItem.getExtAttrName(), connObjectKeyValue), init.getRight().isIgnoreCaseMatch(), MappingUtils.buildOperationOptions(mapItems)); if (connectorObject == null) { throw new NotFoundException( - "Object " + connObjectKeyValue.get() + " with class " + init.getRight().getObjectClass() + "Object " + connObjectKeyValue + " with class " + init.getRight().getObjectClass() + " not found on resource " + key); } diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/MappingManagerImpl.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/MappingManagerImpl.java index fc4ac8b47c4..4fc8fec61bb 100644 --- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/MappingManagerImpl.java +++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/MappingManagerImpl.java @@ -207,7 +207,7 @@ public Pair> prepareAttrs( } } - Optional connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision); + Optional connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision); if (connObjectKeyItem.isPresent()) { Attribute connObjectKeyExtAttr = AttributeUtil.find(connObjectKeyItem.get().getExtAttrName(), attributes); if (connObjectKeyExtAttr != null) { @@ -656,7 +656,7 @@ public List getIntValues( } private String getGroupOwnerValue(final Provision provision, final Any any) { - Optional connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision); + Optional connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision); Pair preparedAttr = null; if (connObjectKeyItem.isPresent()) { diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/VirAttrHandlerImpl.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/VirAttrHandlerImpl.java index 37f9364fc61..d951a4cabf6 100644 --- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/VirAttrHandlerImpl.java +++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/VirAttrHandlerImpl.java @@ -99,7 +99,7 @@ private Map> getValues(final Any any, final Set { LOG.debug("About to read from {}: {}", provision, schemasToRead); - Optional connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision); + Optional connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision); String connObjectKeyValue = connObjectKeyItem.isPresent() ? mappingManager.getConnObjectKeyValue(any, provision).orElse(null) : null; diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AbstractAnyDataBinder.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AbstractAnyDataBinder.java index 4f51593fd6d..28f44afe1ba 100644 --- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AbstractAnyDataBinder.java +++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AbstractAnyDataBinder.java @@ -181,7 +181,7 @@ private void fillAttr( ? values : (values.isEmpty() ? Collections.emptyList() - : Collections.singletonList(values.iterator().next())); + : Collections.singletonList(values.get(0))); valuesProvided.forEach(value -> { if (StringUtils.isBlank(value)) { @@ -313,7 +313,7 @@ protected void processAttrPatch( List valuesToBeAdded = patch.getAttrTO().getValues(); if (!valuesToBeAdded.isEmpty() && (!schema.isUniqueConstraint() || attr.getUniqueValue() == null - || !valuesToBeAdded.iterator().next().equals(attr.getUniqueValue().getValueAsString()))) { + || !valuesToBeAdded.get(0).equals(attr.getUniqueValue().getValueAsString()))) { fillAttr(valuesToBeAdded, anyUtils, schema, attr, invalidValues); } @@ -633,21 +633,18 @@ protected MembershipTO getMembershipTO( protected Map getConnObjectKeys(final Any any, final AnyUtils anyUtils) { Map connObjectKeys = new HashMap<>(); - Iterable iterable = anyUtils.getAllResources(any); - anyUtils.getAllResources(any).forEach(resource -> { - Optional provision = resource.getProvision(any.getType()); - if (provision.isPresent() && provision.get().getMapping() != null) { - Optional connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision.get()); - if (!connObjectKeyItem.isPresent()) { - throw new NotFoundException( + anyUtils.getAllResources(any). + forEach(resource -> resource.getProvision(any.getType()). + filter(provision -> provision.getMapping() != null). + ifPresent(provision -> { + MappingItem connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision). + orElseThrow(() -> new NotFoundException( "ConnObjectKey mapping for " + any.getType().getKey() + " " + any.getKey() - + " on resource '" + resource.getKey() + "'"); - } + + " on resource '" + resource.getKey() + "'")); - mappingManager.getConnObjectKeyValue(any, provision.get()). - ifPresent(connObjectKey -> connObjectKeys.put(resource.getKey(), connObjectKey)); - } - }); + mappingManager.getConnObjectKeyValue(any, provision). + ifPresent(value -> connObjectKeys.put(resource.getKey(), value)); + })); return connObjectKeys; } diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/report/ReconciliationReportlet.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/report/ReconciliationReportlet.java index 63c64578840..91d440e2e9d 100644 --- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/report/ReconciliationReportlet.java +++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/job/report/ReconciliationReportlet.java @@ -286,7 +286,7 @@ private void doExtract(final ContentHandler handler, final List AnyUtils anyUtils = anyUtilsFactory.getInstance(any); anyUtils.getAllResources(any).forEach(resource -> { Provision provision = resource.getProvision(any.getType()).orElse(null); - Optional connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision); + Optional connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision); final String connObjectKeyValue = connObjectKeyItem.isPresent() ? mappingManager.getConnObjectKeyValue(any, provision).get() : StringUtils.EMPTY; diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/propagation/AbstractPropagationTaskExecutor.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/propagation/AbstractPropagationTaskExecutor.java index 766f345b047..184fc280ae0 100644 --- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/propagation/AbstractPropagationTaskExecutor.java +++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/propagation/AbstractPropagationTaskExecutor.java @@ -616,7 +616,7 @@ protected ConnectorObject getRemoteObject( map(schema -> schema.asLinkingMappingItem()).collect(Collectors.toSet()); ConnectorObject obj = null; - Optional connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision); + Optional connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision); if (connObjectKeyItem.isPresent()) { try { obj = connector.getObject( diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/PullUtils.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/PullUtils.java index 84b3661e4c5..2344c69614f 100644 --- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/PullUtils.java +++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/PullUtils.java @@ -174,7 +174,7 @@ private List findByConnObjectKey( String connObjectKey = null; - Optional connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision); + Optional connObjectKeyItem = MappingUtils.getConnObjectKeyItem(provision); if (connObjectKeyItem.isPresent()) { Attribute connObjectKeyAttr = connObj.getAttributeByName(connObjectKeyItem.get().getExtAttrName()); if (connObjectKeyAttr != null) { diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/PushUtils.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/PushUtils.java index 7262a0a4375..65a34b7cfa1 100644 --- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/PushUtils.java +++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/PushUtils.java @@ -108,7 +108,7 @@ public List findByConnObjectKey( final Any any, final Provision provision) { - Optional connObjectKey = MappingUtils.getConnObjectKeyItem(provision); + Optional connObjectKey = MappingUtils.getConnObjectKeyItem(provision); Optional connObjectKeyValue = mappingManager.getConnObjectKeyValue(any, provision); ConnectorObject obj = null; diff --git a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/utils/MappingUtils.java b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/utils/MappingUtils.java index 398fef53e24..5d0c9d261fd 100644 --- a/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/utils/MappingUtils.java +++ b/core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/utils/MappingUtils.java @@ -55,15 +55,15 @@ public final class MappingUtils { private static final Logger LOG = LoggerFactory.getLogger(MappingUtils.class); - public static Optional getConnObjectKeyItem(final Provision provision) { + public static Optional getConnObjectKeyItem(final Provision provision) { Mapping mapping = null; if (provision != null) { mapping = provision.getMapping(); } - return Optional.ofNullable(mapping == null - ? null - : mapping.getConnObjectKeyItem().get()); + return mapping == null + ? Optional.empty() + : mapping.getConnObjectKeyItem(); } public static List getPropagationItems(final List items) {