[SYNCOPE-938] Maximizing usage of Optional#ifPresent
authorFrancesco Chicchiriccò <ilgrosso@apache.org>
Mon, 23 Apr 2018 07:57:04 +0000 (09:57 +0200)
committerFrancesco Chicchiriccò <ilgrosso@apache.org>
Mon, 23 Apr 2018 07:57:04 +0000 (09:57 +0200)
20 files changed:
client/cli/src/main/java/org/apache/syncope/client/cli/commands/info/Info.java
client/console/src/main/java/org/apache/syncope/client/console/panels/TypeExtensionDirectoryPanel.java
client/console/src/main/java/org/apache/syncope/client/console/wicket/markup/html/bootstrap/dialog/BaseModal.java
client/console/src/main/java/org/apache/syncope/client/console/widgets/ReconciliationWidget.java
client/console/src/main/java/org/apache/syncope/client/console/wizards/resources/ConnectorConfPanel.java
client/enduser/src/main/java/org/apache/syncope/client/enduser/resources/UserSelfUpdateResource.java
common/lib/src/main/java/org/apache/syncope/common/lib/AnyOperations.java
core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/DefaultAccountRule.java
core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/DefaultPasswordRule.java
core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/dao/JPAUserDAO.java
core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/DefaultGroupProvisioningManager.java
core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AbstractAnyDataBinder.java
core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/AnyObjectDataBinderImpl.java
core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/data/UserDataBinderImpl.java
core/provisioning-java/src/main/java/org/apache/syncope/core/provisioning/java/pushpull/PullJobDelegate.java
core/rest-cxf/src/main/java/org/apache/syncope/core/rest/cxf/WadlGenerator.java
core/spring/src/main/java/org/apache/syncope/core/spring/security/DefaultPasswordGenerator.java
ext/camel/provisioning-camel/src/main/java/org/apache/syncope/core/provisioning/camel/producer/CreateProducer.java
ext/saml2sp/logic/src/main/java/org/apache/syncope/core/logic/saml2/SAML2UserManager.java
ext/scimv2/logic/src/main/java/org/apache/syncope/core/logic/SCIMDataBinder.java

index f766f16..8167cc5 100644 (file)
@@ -18,9 +18,7 @@
  */
 package org.apache.syncope.client.cli.commands.info;
 
-import java.util.Optional;
 import org.apache.syncope.client.cli.SyncopeServices;
-import org.apache.syncope.common.lib.info.JavaImplInfo;
 import org.apache.syncope.common.lib.info.PlatformInfo;
 import org.apache.syncope.common.lib.types.ImplementationType;
 import org.apache.syncope.common.rest.api.service.SyncopeService;
@@ -97,15 +95,14 @@ public class Info {
     }
 
     public void accountRules() {
-        Optional<JavaImplInfo> info = platformInfo.getJavaImplInfo(ImplementationType.ACCOUNT_RULE);
-        if (info.isPresent()) {
+        platformInfo.getJavaImplInfo(ImplementationType.ACCOUNT_RULE).ifPresent(info -> {
             try {
-                infoResultManager.printAccountRules(info.get().getClasses());
+                infoResultManager.printAccountRules(info.getClasses());
             } catch (final Exception ex) {
                 LOG.error("Information error", ex);
                 infoResultManager.genericError(ex.getMessage());
             }
-        }
+        });
     }
 
     public void connidLocations() {
@@ -118,135 +115,124 @@ public class Info {
     }
 
     public void reconFilterBuilders() {
-        Optional<JavaImplInfo> info = platformInfo.getJavaImplInfo(ImplementationType.RECON_FILTER_BUILDER);
-        if (info.isPresent()) {
+        platformInfo.getJavaImplInfo(ImplementationType.RECON_FILTER_BUILDER).ifPresent(info -> {
             try {
-                infoResultManager.printReconFilterBuilders(info.get().getClasses());
+                infoResultManager.printAccountRules(info.getClasses());
             } catch (final Exception ex) {
                 LOG.error("Information error", ex);
                 infoResultManager.genericError(ex.getMessage());
             }
-        }
+        });
     }
 
     public void logicActions() {
-        Optional<JavaImplInfo> info = platformInfo.getJavaImplInfo(ImplementationType.LOGIC_ACTIONS);
-        if (info.isPresent()) {
+        platformInfo.getJavaImplInfo(ImplementationType.LOGIC_ACTIONS).ifPresent(info -> {
             try {
-                infoResultManager.printLogicActions(info.get().getClasses());
+                infoResultManager.printAccountRules(info.getClasses());
             } catch (final Exception ex) {
                 LOG.error("Information error", ex);
                 infoResultManager.genericError(ex.getMessage());
             }
-        }
+        });
     }
 
     public void itemTransformers() {
-        Optional<JavaImplInfo> info = platformInfo.getJavaImplInfo(ImplementationType.ITEM_TRANSFORMER);
-        if (info.isPresent()) {
+        platformInfo.getJavaImplInfo(ImplementationType.ITEM_TRANSFORMER).ifPresent(info -> {
             try {
-                infoResultManager.printItemTransformers(info.get().getClasses());
+                infoResultManager.printAccountRules(info.getClasses());
             } catch (final Exception ex) {
                 LOG.error("Information error", ex);
                 infoResultManager.genericError(ex.getMessage());
             }
-        }
+        });
     }
 
     public void passwordRules() {
-        Optional<JavaImplInfo> info = platformInfo.getJavaImplInfo(ImplementationType.PASSWORD_RULE);
-        if (info.isPresent()) {
+        platformInfo.getJavaImplInfo(ImplementationType.PASSWORD_RULE).ifPresent(info -> {
             try {
-                infoResultManager.printPasswordRules(info.get().getClasses());
+                infoResultManager.printAccountRules(info.getClasses());
             } catch (final Exception ex) {
                 LOG.error("Information error", ex);
                 infoResultManager.genericError(ex.getMessage());
             }
-        }
+        });
     }
 
     public void propagationActions() {
-        Optional<JavaImplInfo> info = platformInfo.getJavaImplInfo(ImplementationType.PROPAGATION_ACTIONS);
-        if (info.isPresent()) {
+        platformInfo.getJavaImplInfo(ImplementationType.PROPAGATION_ACTIONS).ifPresent(info -> {
             try {
-                infoResultManager.printPropagationActions(info.get().getClasses());
+                infoResultManager.printAccountRules(info.getClasses());
             } catch (final Exception ex) {
                 LOG.error("Information error", ex);
                 infoResultManager.genericError(ex.getMessage());
             }
-        }
+        });
     }
 
     public void pushActions() {
-        Optional<JavaImplInfo> info = platformInfo.getJavaImplInfo(ImplementationType.PUSH_ACTIONS);
-        if (info.isPresent()) {
+        platformInfo.getJavaImplInfo(ImplementationType.PUSH_ACTIONS).ifPresent(info -> {
             try {
-                infoResultManager.printPushActions(info.get().getClasses());
+                infoResultManager.printAccountRules(info.getClasses());
             } catch (final Exception ex) {
                 LOG.error("Information error", ex);
                 infoResultManager.genericError(ex.getMessage());
             }
-        }
+        });
     }
 
     public void reportletConfs() {
-        Optional<JavaImplInfo> info = platformInfo.getJavaImplInfo(ImplementationType.REPORTLET);
-        if (info.isPresent()) {
+        platformInfo.getJavaImplInfo(ImplementationType.REPORTLET).ifPresent(info -> {
             try {
-                infoResultManager.printReportletConfs(info.get().getClasses());
+                infoResultManager.printAccountRules(info.getClasses());
             } catch (final Exception ex) {
                 LOG.error("Information error", ex);
                 infoResultManager.genericError(ex.getMessage());
             }
-        }
+        });
     }
 
     public void pullActions() {
-        Optional<JavaImplInfo> info = platformInfo.getJavaImplInfo(ImplementationType.PULL_ACTIONS);
-        if (info.isPresent()) {
+        platformInfo.getJavaImplInfo(ImplementationType.PULL_ACTIONS).ifPresent(info -> {
             try {
-                infoResultManager.printPullActions(info.get().getClasses());
+                infoResultManager.printAccountRules(info.getClasses());
             } catch (final Exception ex) {
                 LOG.error("Information error", ex);
                 infoResultManager.genericError(ex.getMessage());
             }
-        }
+        });
     }
 
     public void pullCorrelationRules() {
-        Optional<JavaImplInfo> info = platformInfo.getJavaImplInfo(ImplementationType.PULL_CORRELATION_RULE);
-        if (info.isPresent()) {
+        platformInfo.getJavaImplInfo(ImplementationType.PULL_CORRELATION_RULE).ifPresent(info -> {
             try {
-                infoResultManager.printCorrelationRules(info.get().getClasses());
+                infoResultManager.printAccountRules(info.getClasses());
             } catch (final Exception ex) {
                 LOG.error("Information error", ex);
                 infoResultManager.genericError(ex.getMessage());
             }
-        }
+        });
     }
 
     public void taskJobs() {
-        Optional<JavaImplInfo> info = platformInfo.getJavaImplInfo(ImplementationType.TASKJOB_DELEGATE);
-        if (info.isPresent()) {
+        platformInfo.getJavaImplInfo(ImplementationType.TASKJOB_DELEGATE).ifPresent(info -> {
             try {
-                infoResultManager.printJobs(info.get().getClasses());
+                infoResultManager.printAccountRules(info.getClasses());
             } catch (final Exception ex) {
                 LOG.error("Information error", ex);
                 infoResultManager.genericError(ex.getMessage());
             }
-        }
+        });
     }
 
     public void validators() {
-        Optional<JavaImplInfo> info = platformInfo.getJavaImplInfo(ImplementationType.VALIDATOR);
-        if (info.isPresent()) {
+        platformInfo.getJavaImplInfo(ImplementationType.VALIDATOR).ifPresent(info -> {
             try {
-                infoResultManager.printValidators(info.get().getClasses());
+                infoResultManager.printAccountRules(info.getClasses());
             } catch (final Exception ex) {
                 LOG.error("Information error", ex);
                 infoResultManager.genericError(ex.getMessage());
             }
-        }
+        });
     }
 
     public void passwordGenerator() {
index 818ef7d..08a3147 100644 (file)
@@ -24,7 +24,6 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Optional;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.client.console.SyncopeConsoleSession;
 import org.apache.syncope.client.console.commons.Constants;
@@ -155,11 +154,10 @@ public class TypeExtensionDirectoryPanel
 
             @Override
             public void onClick(final AjaxRequestTarget target, final TypeExtensionTO ignore) {
-                Optional<TypeExtensionTO> typeExt = groupTO.getTypeExtension(typeExtension.getAnyType());
-                if (typeExt.isPresent()) {
-                    groupTO.getTypeExtensions().remove(typeExt.get());
+                groupTO.getTypeExtension(typeExtension.getAnyType()).ifPresent(typeExt -> {
+                    groupTO.getTypeExtensions().remove(typeExt);
                     target.add(container);
-                }
+                });
             }
         }, ActionLink.ActionType.DELETE, StringUtils.EMPTY, true);
         return panel;
index b9eb922..6948aca 100644 (file)
@@ -24,7 +24,6 @@ import de.agilecoders.wicket.extensions.markup.html.bootstrap.behavior.Draggable
 import java.io.Serializable;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Optional;
 import org.apache.syncope.client.console.panels.AbstractModalPanel;
 import org.apache.syncope.client.console.panels.ModalPanel;
 import org.apache.syncope.client.console.panels.NotificationPanel;
@@ -215,7 +214,7 @@ public class BaseModal<T extends Serializable> extends Modal<T> {
 
         if (submitButton == null) {
             submitButton = submit;
-            this.components.add(submitButton);
+            components.add(submitButton);
         } else {
             submitButton.replaceWith(submit);
             submitButton = submit;
@@ -229,11 +228,10 @@ public class BaseModal<T extends Serializable> extends Modal<T> {
             throw new IllegalStateException();
         }
 
-        Optional<Component> button =
-                this.components.stream().filter(component -> SUBMIT.equals(component.getId())).findAny();
-        if (button.isPresent()) {
-            this.components.remove(button.get());
-        }
+        components.stream().
+                filter(component -> SUBMIT.equals(component.getId())).
+                findFirst().
+                ifPresent(button -> components.remove(button));
 
         submitButton = null;
     }
index 475f6e9..8723a7d 100644 (file)
@@ -56,7 +56,6 @@ import org.apache.syncope.client.console.widgets.reconciliation.ReconciliationRe
 import org.apache.syncope.client.console.widgets.reconciliation.ReconciliationReportParser;
 import org.apache.syncope.client.console.wizards.WizardMgtPanel;
 import org.apache.syncope.common.lib.to.ExecTO;
-import org.apache.syncope.common.lib.to.JobTO;
 import org.apache.syncope.common.lib.to.ReportTO;
 import org.apache.syncope.common.lib.types.AnyTypeKind;
 import org.apache.syncope.common.lib.types.ReportExecExportFormat;
@@ -122,20 +121,22 @@ public class ReconciliationWidget extends BaseWidget {
             protected void onTimer(final AjaxRequestTarget target) {
                 if (isCheckReconciliationJob()) {
                     try {
-                        Optional<JobTO> reportJobTO = restClient.listJobs().stream().
+                        restClient.listJobs().stream().
                                 filter(jobTO -> SyncopeConsoleApplication.get().
-                                getReconciliationReportKey().equals(jobTO.getRefKey())).findAny();
-                        if (reportJobTO.isPresent() && !reportJobTO.get().isRunning()) {
-                            LOG.debug("Report {} is not running",
-                                    SyncopeConsoleApplication.get().getReconciliationReportKey());
+                                getReconciliationReportKey().equals(jobTO.getRefKey())).
+                                findFirst().ifPresent(reportJobTO -> {
+                                    if (!reportJobTO.isRunning()) {
+                                        LOG.debug("Report {} is not running",
+                                                SyncopeConsoleApplication.get().getReconciliationReportKey());
 
-                            overlay.setVisible(false);
+                                        overlay.setVisible(false);
 
-                            container.addOrReplace(buildExecFragment());
+                                        container.addOrReplace(buildExecFragment());
 
-                            target.add(ReconciliationWidget.this);
-                            setCheckReconciliationJob(false);
-                        }
+                                        target.add(ReconciliationWidget.this);
+                                        setCheckReconciliationJob(false);
+                                    }
+                                });
                     } catch (Throwable t) {
                         LOG.error("Unexpected error while checking for updated reconciliation job info", t);
                     }
@@ -267,7 +268,7 @@ public class ReconciliationWidget extends BaseWidget {
         Optional<ExecTO> exec = Optional.empty();
         if (SyncopeConsoleSession.get().owns(StandardEntitlement.REPORT_LIST)) {
             exec = restClient.listRecentExecutions(ROWS).stream().
-                    filter(e -> reconciliationReportKey.equals(e.getRefKey())).findAny();
+                    filter(e -> reconciliationReportKey.equals(e.getRefKey())).findFirst();
         }
         if (!exec.isPresent()) {
             LOG.error("Could not find the last execution of reconciliation report");
@@ -391,11 +392,10 @@ public class ReconciliationWidget extends BaseWidget {
                             final String componentId,
                             final IModel<Any> rowModel) {
 
-                        final Any any = rowModel.getObject();
+                        Any any = rowModel.getObject();
 
-                        Optional<Missing> missing =
-                                any.getMissing().stream().
-                                        filter(object -> resource.equals(object.getResource())).findAny();
+                        Optional<Missing> missing = any.getMissing().stream().
+                                filter(object -> resource.equals(object.getResource())).findFirst();
                         List<Misaligned> misaligned = any.getMisaligned().stream().
                                 filter(object -> resource.equals(object.getResource())).collect(Collectors.toList());
 
@@ -404,7 +404,7 @@ public class ReconciliationWidget extends BaseWidget {
                             if (misaligned == null || misaligned.isEmpty()) {
                                 content = new Label(componentId, StringUtils.EMPTY);
                             } else {
-                                final Action<Any> action = new Action<>(new ActionLink<Any>() {
+                                Action<Any> action = new Action<>(new ActionLink<Any>() {
 
                                     private static final long serialVersionUID = -3722207913631435501L;
 
@@ -427,7 +427,7 @@ public class ReconciliationWidget extends BaseWidget {
                                 content = new ActionPanel<>(componentId, rowModel, action);
                             }
                         } else {
-                            final Action<Any> action = new Action<>(null, ActionLink.ActionType.NOT_FOUND);
+                            Action<Any> action = new Action<>(null, ActionLink.ActionType.NOT_FOUND);
                             action.hideLabel();
                             content = new ActionPanel<>(componentId, rowModel, action);
                         }
index f2a3a1e..130012e 100644 (file)
@@ -20,7 +20,6 @@ package org.apache.syncope.client.console.wizards.resources;
 
 import java.util.Collections;
 import java.util.List;
-import java.util.Optional;
 import java.util.stream.Collectors;
 import org.apache.syncope.common.lib.to.ConnBundleTO;
 import org.apache.syncope.common.lib.to.ConnInstanceTO;
@@ -76,11 +75,12 @@ public abstract class ConnectorConfPanel extends AbstractConnConfPanel<ConnInsta
                     ConnConfProperty property = new ConnConfProperty();
                     property.setSchema(key);
 
-                    Optional<ConnConfProperty> conf = instance.getConf(key.getName());
-                    if (conf.isPresent() && conf.get().getValues() != null) {
-                        property.getValues().addAll(conf.get().getValues());
-                        property.setOverridable(conf.get().isOverridable());
-                    }
+                    instance.getConf(key.getName()).ifPresent(conf -> {
+                        if (conf.getValues() != null) {
+                            property.getValues().addAll(conf.getValues());
+                            property.setOverridable(conf.isOverridable());
+                        }
+                    });
 
                     if (property.getValues().isEmpty() && !key.getDefaultValues().isEmpty()) {
                         property.getValues().addAll(key.getDefaultValues());
index dcc6c79..221b744 100644 (file)
@@ -20,7 +20,6 @@ package org.apache.syncope.client.enduser.resources;
 
 import java.util.HashSet;
 import java.util.Map;
-import java.util.Optional;
 import java.util.Set;
 import javax.servlet.http.HttpServletRequest;
 import javax.ws.rs.core.MediaType;
@@ -182,17 +181,16 @@ public class UserSelfUpdateResource extends BaseUserSelfResource {
     private void completeUserObject(final UserTO userTO, final UserTO selfTO) {
         // memberships plain and virtual attrs
         userTO.getMemberships().forEach(updatedTOMemb -> {
-            Optional<MembershipTO> oldTOMatchedMemb = selfTO.getMemberships().stream().
+            selfTO.getMemberships().stream().
                     filter(oldTOMemb -> updatedTOMemb.getGroupKey().equals(oldTOMemb.getGroupKey())).
-                    findFirst();
-            if (oldTOMatchedMemb.isPresent()) {
-                if (!updatedTOMemb.getPlainAttrs().isEmpty()) {
-                    completeAttrs(updatedTOMemb.getPlainAttrs(), oldTOMatchedMemb.get().getPlainAttrs());
-                }
-                if (!updatedTOMemb.getVirAttrs().isEmpty()) {
-                    completeAttrs(updatedTOMemb.getVirAttrs(), oldTOMatchedMemb.get().getVirAttrs());
-                }
-            }
+                    findFirst().ifPresent(oldTOMatchedMemb -> {
+                        if (!updatedTOMemb.getPlainAttrs().isEmpty()) {
+                            completeAttrs(updatedTOMemb.getPlainAttrs(), oldTOMatchedMemb.getPlainAttrs());
+                        }
+                        if (!updatedTOMemb.getVirAttrs().isEmpty()) {
+                            completeAttrs(updatedTOMemb.getVirAttrs(), oldTOMatchedMemb.getVirAttrs());
+                        }
+                    });
         });
         // plain attrs
         completeAttrs(userTO.getPlainAttrs(), selfTO.getPlainAttrs());
index 7340d69..c82dc2d 100644 (file)
@@ -21,7 +21,6 @@ package org.apache.syncope.common.lib;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.Map;
-import java.util.Optional;
 import java.util.Set;
 import org.apache.commons.lang3.SerializationUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -536,11 +535,9 @@ public final class AnyOperations {
                     if (membPatch.getGroup() == null) {
                         LOG.warn("Invalid {} specified: {}", MembershipPatch.class.getName(), membPatch);
                     } else {
-                        Optional<MembershipTO> memb = result.getMemberships().stream().
-                                filter(membership -> membPatch.getGroup().equals(membership.getGroupKey())).findFirst();
-                        if (memb.isPresent()) {
-                            result.getMemberships().remove(memb.get());
-                        }
+                        result.getMemberships().stream().
+                                filter(membership -> membPatch.getGroup().equals(membership.getGroupKey())).
+                                findFirst().ifPresent(memb -> result.getMemberships().remove(memb));
 
                         if (membPatch.getOperation() == PatchOperation.ADD_REPLACE) {
                             MembershipTO newMembershipTO =
@@ -593,11 +590,9 @@ public final class AnyOperations {
                     if (membPatch.getGroup() == null) {
                         LOG.warn("Invalid {} specified: {}", MembershipPatch.class.getName(), membPatch);
                     } else {
-                        Optional<MembershipTO> memb = result.getMemberships().stream().
-                                filter(membership -> membPatch.getGroup().equals(membership.getGroupKey())).findFirst();
-                        if (memb.isPresent()) {
-                            result.getMemberships().remove(memb.get());
-                        }
+                        result.getMemberships().stream().
+                                filter(membership -> membPatch.getGroup().equals(membership.getGroupKey())).
+                                findFirst().ifPresent(memb -> result.getMemberships().remove(memb));
 
                         if (membPatch.getOperation() == PatchOperation.ADD_REPLACE) {
                             MembershipTO newMembershipTO =
index 636b788..41bb0d8 100644 (file)
@@ -18,6 +18,7 @@
  */
 package org.apache.syncope.core.persistence.jpa.dao;
 
+import java.util.Optional;
 import java.util.regex.Pattern;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.common.lib.policy.AccountRuleConf;
@@ -50,7 +51,7 @@ public class DefaultAccountRule implements AccountRule {
     public void enforce(final User user) {
         this.conf.getSchemasNotPermitted().stream().
                 map(schema -> user.getPlainAttr(schema)).
-                filter(attr -> attr.isPresent()).
+                filter(Optional::isPresent).
                 map(attr -> attr.get().getValuesAsStrings()).
                 filter(values -> (values != null && !values.isEmpty())).
                 forEachOrdered(values -> this.conf.getWordsNotPermitted().add(values.get(0)));
index d0abddd..98c04bc 100644 (file)
@@ -18,6 +18,7 @@
  */
 package org.apache.syncope.core.persistence.jpa.dao;
 
+import java.util.Optional;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf;
 import org.apache.syncope.common.lib.policy.PasswordRuleConf;
@@ -53,7 +54,7 @@ public class DefaultPasswordRule implements PasswordRule {
     public void enforce(final User user) {
         this.conf.getSchemasNotPermitted().stream().
                 map(schema -> user.getPlainAttr(schema)).
-                filter(attr -> attr.isPresent()).
+                filter(Optional::isPresent).
                 map(attr -> attr.get().getValuesAsStrings()).
                 filter(values -> (values != null && !values.isEmpty())).
                 forEachOrdered(values -> this.conf.getWordsNotPermitted().add(values.get(0)));
index 92f7c0a..67eda83 100644 (file)
@@ -48,7 +48,6 @@ import org.apache.syncope.core.persistence.api.attrvalue.validation.InvalidEntit
 import org.apache.syncope.core.persistence.api.dao.AccessTokenDAO;
 import org.apache.syncope.core.persistence.api.dao.AccountRule;
 import org.apache.syncope.core.persistence.api.dao.GroupDAO;
-import org.apache.syncope.core.persistence.api.dao.PasswordRule;
 import org.apache.syncope.core.persistence.api.dao.RealmDAO;
 import org.apache.syncope.core.persistence.api.dao.RoleDAO;
 import org.apache.syncope.core.persistence.api.dao.UserDAO;
@@ -296,10 +295,7 @@ public class JPAUserDAO extends AbstractAnyDAO<User> implements UserDAO {
                 }
 
                 for (Implementation impl : policy.getRules()) {
-                    Optional<PasswordRule> rule = ImplementationManager.buildPasswordRule(impl);
-                    if (rule.isPresent()) {
-                        rule.get().enforce(user);
-                    }
+                    ImplementationManager.buildPasswordRule(impl).ifPresent(rule -> rule.enforce(user));
                 }
 
                 if (user.verifyPasswordHistory(user.getClearPassword(), policy.getHistoryLength())) {
index ebf1376..98aab4d 100644 (file)
@@ -23,14 +23,12 @@ import java.util.List;
 import java.util.Map;
 import java.util.Collection;
 import java.util.Collections;
-import java.util.Optional;
 import java.util.Set;
 import java.util.stream.Collectors;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.syncope.common.lib.patch.GroupPatch;
-import org.apache.syncope.common.lib.to.AttrTO;
 import org.apache.syncope.common.lib.to.PropagationStatus;
 import org.apache.syncope.common.lib.to.GroupTO;
 import org.apache.syncope.common.lib.to.PropagationTaskTO;
@@ -95,10 +93,8 @@ public class DefaultGroupProvisioningManager implements GroupProvisioningManager
         WorkflowResult<String> created = gwfAdapter.create(groupTO);
 
         // see ConnObjectUtils#getAnyTOFromConnObject for GroupOwnerSchema
-        Optional<AttrTO> groupOwner = groupTO.getPlainAttr(StringUtils.EMPTY);
-        if (groupOwner.isPresent()) {
-            groupOwnerMap.put(created.getResult(), groupOwner.get().getValues().iterator().next());
-        }
+        groupTO.getPlainAttr(StringUtils.EMPTY).ifPresent(groupOwner
+                -> groupOwnerMap.put(created.getResult(), groupOwner.getValues().iterator().next()));
 
         List<PropagationTaskTO> tasks = propagationManager.getCreateTasks(
                 AnyTypeKind.GROUP,
index 4346c1a..5f5d83c 100644 (file)
@@ -330,7 +330,7 @@ abstract class AbstractAnyDataBinder {
         }
 
         resources.stream().
-                filter(resource -> (resource.getProvision(any.getType()).isPresent())
+                filter(resource -> resource.getProvision(any.getType()).isPresent()
                 && resource.getProvision(any.getType()).get().getMapping() != null).
                 forEach(resource -> {
                     MappingUtils.getPropagationItems(
@@ -655,10 +655,8 @@ abstract class AbstractAnyDataBinder {
                             + " on resource '" + resource.getKey() + "'");
                 }
 
-                Optional<String> connObjectKey = mappingManager.getConnObjectKeyValue(any, provision.get());
-                if (connObjectKey.isPresent()) {
-                    connObjectKeys.put(resource.getKey(), connObjectKey.get());
-                }
+                mappingManager.getConnObjectKeyValue(any, provision.get()).
+                        ifPresent(connObjectKey -> connObjectKeys.put(resource.getKey(), connObjectKey));
             }
         });
 
index e6fb612..e09ab0e 100644 (file)
@@ -274,12 +274,11 @@ public class AnyObjectDataBinderImpl extends AbstractAnyDataBinder implements An
             if (relationshipType == null) {
                 LOG.debug("Ignoring invalid relationship type {}", patch.getRelationshipTO().getType());
             } else {
-                Optional<? extends ARelationship> relationship =
-                        anyObject.getRelationship(relationshipType, patch.getRelationshipTO().getOtherEndKey());
-                if (relationship.isPresent()) {
-                    anyObject.getRelationships().remove(relationship.get());
-                    relationship.get().setLeftEnd(null);
-                }
+                anyObject.getRelationship(relationshipType, patch.getRelationshipTO().getOtherEndKey()).
+                        ifPresent(relationship -> {
+                            anyObject.getRelationships().remove(relationship);
+                            relationship.setLeftEnd(null);
+                        });
 
                 if (patch.getOperation() == PatchOperation.ADD_REPLACE) {
                     if (StringUtils.isBlank(patch.getRelationshipTO().getOtherEndType())
@@ -339,24 +338,23 @@ public class AnyObjectDataBinderImpl extends AbstractAnyDataBinder implements An
         // memberships
         anyObjectPatch.getMemberships().stream().
                 filter((membPatch) -> (membPatch.getGroup() != null)).forEachOrdered(membPatch -> {
-            Optional<? extends AMembership> membership = anyObject.getMembership(membPatch.getGroup());
-            if (membership.isPresent()) {
-                anyObject.getMemberships().remove(membership.get());
-                membership.get().setLeftEnd(null);
-                anyObject.getPlainAttrs(membership.get()).forEach(attr -> {
+            anyObject.getMembership(membPatch.getGroup()).ifPresent(membership -> {
+                anyObject.getMemberships().remove(membership);
+                membership.setLeftEnd(null);
+                anyObject.getPlainAttrs(membership).forEach(attr -> {
                     anyObject.remove(attr);
                     attr.setOwner(null);
                 });
 
                 if (membPatch.getOperation() == PatchOperation.DELETE) {
-                    groupDAO.findAllResourceKeys(membership.get().getRightEnd().getKey()).stream().
+                    groupDAO.findAllResourceKeys(membership.getRightEnd().getKey()).stream().
                             filter(resource -> reasons.containsKey(resource)).
                             forEach(resource -> {
-                                reasons.get(resource).remove(membership.get().getRightEnd().getKey());
+                                reasons.get(resource).remove(membership.getRightEnd().getKey());
                                 toBeProvisioned.add(resource);
                             });
                 }
-            }
+            });
             if (membPatch.getOperation() == PatchOperation.ADD_REPLACE) {
                 Group group = groupDAO.find(membPatch.getGroup());
                 if (group == null) {
index 6cffa6b..fa9cb9f 100644 (file)
@@ -374,12 +374,11 @@ public class UserDataBinderImpl extends AbstractAnyDataBinder implements UserDat
             if (relationshipType == null) {
                 LOG.debug("Ignoring invalid relationship type {}", patch.getRelationshipTO().getType());
             } else {
-                Optional<? extends URelationship> relationship =
-                        user.getRelationship(relationshipType, patch.getRelationshipTO().getOtherEndKey());
-                if (relationship.isPresent()) {
-                    user.getRelationships().remove(relationship.get());
-                    relationship.get().setLeftEnd(null);
-                }
+                user.getRelationship(relationshipType, patch.getRelationshipTO().getOtherEndKey()).
+                        ifPresent(relationship -> {
+                            user.getRelationships().remove(relationship);
+                            relationship.setLeftEnd(null);
+                        });
 
                 if (patch.getOperation() == PatchOperation.ADD_REPLACE) {
                     AnyObject otherEnd = anyObjectDAO.find(patch.getRelationshipTO().getOtherEndKey());
@@ -428,25 +427,24 @@ public class UserDataBinderImpl extends AbstractAnyDataBinder implements UserDat
         // memberships
         userPatch.getMemberships().stream().
                 filter(membPatch -> membPatch.getGroup() != null).forEachOrdered((membPatch) -> {
-            Optional<? extends UMembership> membership = user.getMembership(membPatch.getGroup());
-            if (membership.isPresent()) {
-                user.getMemberships().remove(membership.get());
-                membership.get().setLeftEnd(null);
-                user.getPlainAttrs(membership.get()).forEach(attr -> {
+            user.getMembership(membPatch.getGroup()).ifPresent(membership -> {
+                user.getMemberships().remove(membership);
+                membership.setLeftEnd(null);
+                user.getPlainAttrs(membership).forEach(attr -> {
                     user.remove(attr);
                     attr.setOwner(null);
                     attr.setMembership(null);
                 });
 
                 if (membPatch.getOperation() == PatchOperation.DELETE) {
-                    groupDAO.findAllResourceKeys(membership.get().getRightEnd().getKey()).stream().
+                    groupDAO.findAllResourceKeys(membership.getRightEnd().getKey()).stream().
                             filter(resource -> reasons.containsKey(resource)).
                             forEach(resource -> {
-                                reasons.get(resource).remove(membership.get().getRightEnd().getKey());
+                                reasons.get(resource).remove(membership.getRightEnd().getKey());
                                 toBeProvisioned.add(resource);
                             });
                 }
-            }
+            });
             if (membPatch.getOperation() == PatchOperation.ADD_REPLACE) {
                 Group group = groupDAO.find(membPatch.getGroup());
                 if (group == null) {
index 95a4dc1..b813784 100644 (file)
@@ -144,20 +144,16 @@ public class PullJobDelegate extends AbstractProvisioningJobDelegate<PullTask> i
                         ghandler.getProfile().getTask().getResource(),
                         ghandler.getProfile().getConnector(),
                         userIgnoreCaseMatch);
-
                 if (userKey.isPresent()) {
                     group.setUserOwner(userDAO.find(userKey.get()));
                 } else {
-                    Optional<String> groupKey = pullUtils.match(
+                    pullUtils.match(
                             anyTypeDAO.findGroup(),
                             entry.getValue(),
                             ghandler.getProfile().getTask().getResource(),
                             ghandler.getProfile().getConnector(),
-                            groupIgnoreCaseMatch);
-
-                    if (groupKey.isPresent()) {
-                        group.setGroupOwner(groupDAO.find(groupKey.get()));
-                    }
+                            groupIgnoreCaseMatch).
+                            ifPresent(groupKey -> group.setGroupOwner(groupDAO.find(groupKey)));
                 }
             }
             return group;
index e2a1858..2ea790f 100644 (file)
@@ -92,13 +92,12 @@ public class WadlGenerator extends org.apache.cxf.jaxrs.model.wadl.WadlGenerator
                             classResourceInfos.add(cri.get());
                         }
                         cri.get().setResourceClass(beanClass);
-                        continue;
-                    }
-
-                    cri = Optional.ofNullable(ResourceUtils.createClassResourceInfo(
-                            beanClass, beanClass, true, true, BusFactory.getDefaultBus()));
-                    if (cri.isPresent()) {
-                        classResourceInfos.add(cri.get());
+                    } else {
+                        cri = Optional.ofNullable(ResourceUtils.createClassResourceInfo(
+                                beanClass, beanClass, true, true, BusFactory.getDefaultBus()));
+                        if (cri.isPresent()) {
+                            classResourceInfos.add(cri.get());
+                        }
                     }
                 }
 
index b0a4d95..eaa1a96 100644 (file)
@@ -20,10 +20,8 @@ package org.apache.syncope.core.spring.security;
 
 import java.util.ArrayList;
 import java.util.List;
-import java.util.Optional;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.syncope.common.lib.policy.DefaultPasswordRuleConf;
-import org.apache.syncope.core.persistence.api.dao.PasswordRule;
 import org.apache.syncope.core.persistence.api.entity.policy.PasswordPolicy;
 import org.apache.syncope.core.provisioning.api.utils.policy.InvalidPasswordRuleConf;
 import org.apache.syncope.core.provisioning.api.utils.policy.PolicyPattern;
@@ -69,10 +67,11 @@ public class DefaultPasswordGenerator implements PasswordGenerator {
 
         policies.stream().forEach(policy -> policy.getRules().forEach(impl -> {
             try {
-                Optional<PasswordRule> rule = ImplementationManager.buildPasswordRule(impl);
-                if (rule.isPresent() && rule.get().getConf() instanceof DefaultPasswordRuleConf) {
-                    defaultRuleConfs.add((DefaultPasswordRuleConf) rule.get().getConf());
-                }
+                ImplementationManager.buildPasswordRule(impl).ifPresent(rule -> {
+                    if (rule.getConf() instanceof DefaultPasswordRuleConf) {
+                        defaultRuleConfs.add((DefaultPasswordRuleConf) rule.getConf());
+                    }
+                });
             } catch (Exception e) {
                 LOG.error("Invalid {}, ignoring...", impl, e);
             }
index 7b49da6..c18f7a0 100644 (file)
@@ -20,7 +20,6 @@ package org.apache.syncope.core.provisioning.camel.producer;
 
 import java.util.List;
 import java.util.Map;
-import java.util.Optional;
 import java.util.Set;
 
 import org.apache.camel.Endpoint;
@@ -29,7 +28,6 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.tuple.Pair;
 import org.apache.syncope.common.lib.to.AnyObjectTO;
 import org.apache.syncope.common.lib.to.AnyTO;
-import org.apache.syncope.common.lib.to.AttrTO;
 import org.apache.syncope.common.lib.to.GroupTO;
 import org.apache.syncope.common.lib.to.PropagationTaskTO;
 import org.apache.syncope.common.lib.to.UserTO;
@@ -72,10 +70,8 @@ public class CreateProducer extends AbstractProducer {
 
                 if (actual instanceof GroupTO && isPull()) {
                     Map<String, String> groupOwnerMap = exchange.getProperty("groupOwnerMap", Map.class);
-                    Optional<AttrTO> groupOwner = ((GroupTO) actual).getPlainAttr(StringUtils.EMPTY);
-                    if (groupOwner.isPresent()) {
-                        groupOwnerMap.put(created.getResult(), groupOwner.get().getValues().iterator().next());
-                    }
+                    ((GroupTO) actual).getPlainAttr(StringUtils.EMPTY).ifPresent(groupOwner
+                            -> groupOwnerMap.put(created.getResult(), groupOwner.getValues().iterator().next()));
 
                     List<PropagationTaskTO> tasks = getPropagationManager().getCreateTasks(
                             AnyTypeKind.GROUP,
index 3393753..8a70e9a 100644 (file)
@@ -234,11 +234,11 @@ public class SAML2UserManager {
                 switch (intAttrName.getSchemaType()) {
                     case PLAIN:
                         Optional<AttrTO> attr = userTO.getPlainAttr(intAttrName.getSchemaName());
-                        if (!attr.isPresent()) {
+                        if (attr.isPresent()) {
+                            attr.get().getValues().clear();
+                        } else {
                             attr = Optional.of(new AttrTO.Builder().schema(intAttrName.getSchemaName()).build());
                             userTO.getPlainAttrs().add(attr.get());
-                        } else {
-                            attr.get().getValues().clear();
                         }
                         attr.get().getValues().addAll(values);
                         break;
index 80c90d9..8c43c6c 100644 (file)
@@ -428,11 +428,10 @@ public class SCIMDataBinder {
 
         values.forEach(value -> {
             if (value.getType() != null) {
-                Optional<SCIMComplexConf<E>> conf = confs.stream().
-                        filter(object -> value.getType().equals(object.getType().name())).findFirst();
-                if (conf.isPresent()) {
-                    attrs.add(new AttrTO.Builder().schema(conf.get().getValue()).value(value.getValue()).build());
-                }
+                confs.stream().
+                        filter(object -> value.getType().equals(object.getType().name())).findFirst().
+                        ifPresent(conf -> attrs.add(
+                        new AttrTO.Builder().schema(conf.getValue()).value(value.getValue()).build()));
             }
         });
     }