You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by il...@apache.org on 2020/03/02 12:01:27 UTC

[syncope] branch master updated: [SYNCOPE-1531] Fix ignorePaging management

This is an automated email from the ASF dual-hosted git repository.

ilgrosso pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/syncope.git


The following commit(s) were added to refs/heads/master by this push:
     new 31f7915  [SYNCOPE-1531] Fix ignorePaging management
31f7915 is described below

commit 31f7915e12f7218bdd645842e4f4dcf2c1547a10
Author: Francesco Chicchiriccò <il...@apache.org>
AuthorDate: Mon Mar 2 12:51:11 2020 +0100

    [SYNCOPE-1531] Fix ignorePaging management
---
 ...AnyDirectoryPanelAdditionalActionsProvider.java |  2 +-
 .../markup/html/form/AjaxCheckBoxPanel.java        |  6 +--
 .../wicket/ajax/form/AjaxDownloadBehavior.java     | 54 ++++++++++------------
 .../common/rest/api/beans/AbstractCSVSpec.java     | 14 ++++--
 .../syncope/common/rest/api/beans/CSVPushSpec.java | 14 +++---
 .../syncope/core/logic/ReconciliationLogic.java    |  2 +-
 .../core/logic/ReconciliationLogicTest.java        |  3 +-
 .../syncope/fit/core/ReconciliationITCase.java     |  3 +-
 8 files changed, 50 insertions(+), 48 deletions(-)

diff --git a/client/idm/console/src/main/java/org/apache/syncope/client/console/commons/IdMAnyDirectoryPanelAdditionalActionsProvider.java b/client/idm/console/src/main/java/org/apache/syncope/client/console/commons/IdMAnyDirectoryPanelAdditionalActionsProvider.java
index 999575f..8118fc4 100644
--- a/client/idm/console/src/main/java/org/apache/syncope/client/console/commons/IdMAnyDirectoryPanelAdditionalActionsProvider.java
+++ b/client/idm/console/src/main/java/org/apache/syncope/client/console/commons/IdMAnyDirectoryPanelAdditionalActionsProvider.java
@@ -119,7 +119,7 @@ public class IdMAnyDirectoryPanelAdditionalActionsProvider implements AnyDirecto
                     } else if (Constants.OPERATION_SUCCEEDED.equals(payload.getResult())) {
                         target.ifPresent(t -> {
                             if (csvDownloadBehavior.hasResponse()) {
-                                csvDownloadBehavior.initiate(target.get());
+                                csvDownloadBehavior.initiate(t);
                             }
                             modal.close(t);
                         });
diff --git a/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/markup/html/form/AjaxCheckBoxPanel.java b/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/markup/html/form/AjaxCheckBoxPanel.java
index 0ec0bd0..383d20d 100644
--- a/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/markup/html/form/AjaxCheckBoxPanel.java
+++ b/client/idrepo/common-ui/src/main/java/org/apache/syncope/client/ui/commons/markup/html/form/AjaxCheckBoxPanel.java
@@ -21,7 +21,6 @@ package org.apache.syncope.client.ui.commons.markup.html.form;
 import java.io.Serializable;
 import java.util.List;
 import java.util.Optional;
-
 import org.apache.syncope.client.ui.commons.Constants;
 import org.apache.syncope.client.ui.commons.ajax.form.IndicatorAjaxFormComponentUpdatingBehavior;
 import org.apache.syncope.common.lib.Attributable;
@@ -42,6 +41,7 @@ public class AjaxCheckBoxPanel extends FieldPanel<Boolean> {
 
     public AjaxCheckBoxPanel(
             final String id, final String name, final IModel<Boolean> model, final boolean enableOnChange) {
+
         super(id, name, model);
 
         field = new CheckBox("checkboxField", model);
@@ -118,7 +118,7 @@ public class AjaxCheckBoxPanel extends FieldPanel<Boolean> {
             @SuppressWarnings("unchecked")
             public void setObject(final Boolean object) {
                 item.setModelObject(Optional.ofNullable(object)
-                    .map(Object::toString).orElseGet(Boolean.FALSE::toString));
+                        .map(Object::toString).orElseGet(Boolean.FALSE::toString));
             }
         };
 
@@ -127,6 +127,7 @@ public class AjaxCheckBoxPanel extends FieldPanel<Boolean> {
     }
 
     @SuppressWarnings({ "rawtypes", "unchecked" })
+    @Override
     public FieldPanel<Boolean> setNewModel(final Attributable attributableTO, final String schema) {
         field.setModel(new Model() {
 
@@ -152,5 +153,4 @@ public class AjaxCheckBoxPanel extends FieldPanel<Boolean> {
 
         return this;
     }
-
 }
diff --git a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wicket/ajax/form/AjaxDownloadBehavior.java b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wicket/ajax/form/AjaxDownloadBehavior.java
index 733946f..01cf3ec 100644
--- a/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wicket/ajax/form/AjaxDownloadBehavior.java
+++ b/client/idrepo/console/src/main/java/org/apache/syncope/client/console/wicket/ajax/form/AjaxDownloadBehavior.java
@@ -24,7 +24,6 @@ import org.apache.syncope.client.ui.commons.HttpResourceStream;
 import org.apache.wicket.ajax.AjaxRequestTarget;
 import org.apache.wicket.behavior.AbstractAjaxBehavior;
 import org.apache.wicket.request.handler.resource.ResourceStreamRequestHandler;
-import org.apache.wicket.util.resource.IResourceStream;
 import org.apache.wicket.util.time.Duration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -37,7 +36,13 @@ public class AjaxDownloadBehavior extends AbstractAjaxBehavior {
 
     protected SerializableSupplier<Response> response;
 
-    protected HttpResourceStream stream;
+    public boolean hasResponse() {
+        return response != null;
+    }
+
+    public void setResponse(final SerializableSupplier<Response> response) {
+        this.response = response;
+    }
 
     /**
      * Call this method to initiate the download.
@@ -49,40 +54,29 @@ public class AjaxDownloadBehavior extends AbstractAjaxBehavior {
         target.appendJavaScript("window.location.href='" + url + "'");
     }
 
-    @Override
-    public void onRequest() {
-        try {
-            getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(
-                    new ResourceStreamRequestHandler(
-                            getResourceStream(), getFileName()).setCacheDuration(Duration.NONE));
-        } catch (Exception e) {
-            // cannot be notifies because the use of scheduleRequestHandlerAfterCurrent
-            LOG.error("Error downloading file", e);
-        }
-    }
+    protected HttpResourceStream getResourceStream() {
+        HttpResourceStream stream = null;
 
-    public boolean hasResponse() {
-        return response != null;
-    }
-
-    public void setResponse(final SerializableSupplier<Response> response) {
-        this.response = response;
-    }
-
-    private void createResourceStream() {
-        if (stream == null && response != null) {
+        if (response != null) {
             stream = new HttpResourceStream(response.get());
             response = null;
         }
-    }
 
-    protected String getFileName() {
-        createResourceStream();
-        return stream == null ? null : stream.getFilename();
+        return stream;
     }
 
-    protected IResourceStream getResourceStream() {
-        createResourceStream();
-        return stream;
+    @Override
+    public void onRequest() {
+        try {
+            HttpResourceStream resourceStream = getResourceStream();
+            if (resourceStream != null) {
+                getComponent().getRequestCycle().scheduleRequestHandlerAfterCurrent(
+                        new ResourceStreamRequestHandler(
+                                resourceStream, resourceStream.getFilename()).setCacheDuration(Duration.NONE));
+            }
+        } catch (Exception e) {
+            // cannot be notifies beacause the use of scheduleRequestHandlerAfterCurrent
+            LOG.error("Error downloading file", e);
+        }
     }
 }
diff --git a/common/idm/rest-api/src/main/java/org/apache/syncope/common/rest/api/beans/AbstractCSVSpec.java b/common/idm/rest-api/src/main/java/org/apache/syncope/common/rest/api/beans/AbstractCSVSpec.java
index 192ce44..098bbfc 100644
--- a/common/idm/rest-api/src/main/java/org/apache/syncope/common/rest/api/beans/AbstractCSVSpec.java
+++ b/common/idm/rest-api/src/main/java/org/apache/syncope/common/rest/api/beans/AbstractCSVSpec.java
@@ -47,6 +47,10 @@ public abstract class AbstractCSVSpec implements Serializable {
 
     private static final String PARAM_ALLOWCOMMENTS = "allowComments";
 
+    private static final String PARAM_MATCHING_RULE = "matchingRule";
+
+    private static final String PARAM_UNMATCHING_RULE = "unmatchingRule";
+
     protected abstract static class Builder<T extends AbstractCSVSpec, B extends Builder<T, B>> {
 
         protected T instance;
@@ -207,7 +211,7 @@ public abstract class AbstractCSVSpec implements Serializable {
     }
 
     @Parameter(name = PARAM_LINESEPARATOR, description = "character used to separate data rows", schema =
-            @Schema(implementation = String.class, defaultValue = "\\\n"))
+            @Schema(implementation = String.class, defaultValue = "\\u000a"))
     public String getLineSeparator() {
         return lineSeparator;
     }
@@ -241,20 +245,24 @@ public abstract class AbstractCSVSpec implements Serializable {
         this.allowComments = allowComments;
     }
 
+    @Parameter(name = PARAM_UNMATCHING_RULE, required = true, schema =
+            @Schema(implementation = UnmatchingRule.class, defaultValue = "PROVISION"))
     public UnmatchingRule getUnmatchingRule() {
         return unmatchingRule;
     }
 
-    @QueryParam("unmatchingRule")
+    @QueryParam(PARAM_UNMATCHING_RULE)
     public void setUnmatchingRule(final UnmatchingRule unmatchingRule) {
         this.unmatchingRule = unmatchingRule;
     }
 
+    @Parameter(name = PARAM_MATCHING_RULE, required = true, schema =
+            @Schema(implementation = MatchingRule.class, defaultValue = "UPDATE"))
     public MatchingRule getMatchingRule() {
         return matchingRule;
     }
 
-    @QueryParam("matchingRule")
+    @QueryParam(PARAM_MATCHING_RULE)
     public void setMatchingRule(final MatchingRule matchingRule) {
         this.matchingRule = matchingRule;
     }
diff --git a/common/idm/rest-api/src/main/java/org/apache/syncope/common/rest/api/beans/CSVPushSpec.java b/common/idm/rest-api/src/main/java/org/apache/syncope/common/rest/api/beans/CSVPushSpec.java
index 0a68810..d3f34d8 100644
--- a/common/idm/rest-api/src/main/java/org/apache/syncope/common/rest/api/beans/CSVPushSpec.java
+++ b/common/idm/rest-api/src/main/java/org/apache/syncope/common/rest/api/beans/CSVPushSpec.java
@@ -21,6 +21,7 @@ package org.apache.syncope.common.rest.api.beans;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import javax.ws.rs.DefaultValue;
 import javax.ws.rs.QueryParam;
 
 public class CSVPushSpec extends AbstractCSVSpec {
@@ -78,8 +79,8 @@ public class CSVPushSpec extends AbstractCSVSpec {
             return this;
         }
 
-        public Builder ignorePagination(final boolean ignorePagination) {
-            getInstance().setIgnorePaging(ignorePagination);
+        public Builder ignorePaging(final boolean ignorePaging) {
+            getInstance().setIgnorePaging(ignorePaging);
             return this;
         }
 
@@ -97,7 +98,7 @@ public class CSVPushSpec extends AbstractCSVSpec {
 
     private List<String> virAttrs = new ArrayList<>();
 
-    private boolean ignorePaging;
+    private Boolean ignorePaging;
 
     protected List<String> propagationActions = new ArrayList<>();
 
@@ -137,12 +138,13 @@ public class CSVPushSpec extends AbstractCSVSpec {
         this.virAttrs = virAttrs;
     }
 
-    public boolean isIgnorePaging() {
-        return ignorePaging;
+    public Boolean getIgnorePaging() {
+        return ignorePaging == null ? Boolean.FALSE : ignorePaging;
     }
 
     @QueryParam("ignorePaging")
-    public void setIgnorePaging(final boolean ignorePaging) {
+    @DefaultValue("false")
+    public void setIgnorePaging(final Boolean ignorePaging) {
         this.ignorePaging = ignorePaging;
     }
 
diff --git a/core/idm/logic/src/main/java/org/apache/syncope/core/logic/ReconciliationLogic.java b/core/idm/logic/src/main/java/org/apache/syncope/core/logic/ReconciliationLogic.java
index 026f209..9b749ce 100644
--- a/core/idm/logic/src/main/java/org/apache/syncope/core/logic/ReconciliationLogic.java
+++ b/core/idm/logic/src/main/java/org/apache/syncope/core/logic/ReconciliationLogic.java
@@ -430,7 +430,7 @@ public class ReconciliationLogic extends AbstractTransactionalLogic<EntityTO> {
         SearchCond effectiveCond = searchCond == null ? anyUtils.dao().getAllMatchingCond() : searchCond;
 
         List<Any<?>> matching;
-        if (spec.isIgnorePaging()) {
+        if (spec.getIgnorePaging()) {
             matching = new ArrayList<>();
 
             int count = searchDAO.count(adminRealms, searchCond, anyType.getKind());
diff --git a/core/idm/logic/src/test/java/org/apache/syncope/core/logic/ReconciliationLogicTest.java b/core/idm/logic/src/test/java/org/apache/syncope/core/logic/ReconciliationLogicTest.java
index 73064c6..7fb1f9e 100644
--- a/core/idm/logic/src/test/java/org/apache/syncope/core/logic/ReconciliationLogicTest.java
+++ b/core/idm/logic/src/test/java/org/apache/syncope/core/logic/ReconciliationLogicTest.java
@@ -92,8 +92,7 @@ public class ReconciliationLogicTest extends AbstractTest {
                 () -> userLogic.search(null, 1, 100, List.of(), SyncopeConstants.ROOT_REALM, false));
         assertNotNull(search);
 
-        CSVPushSpec spec = new CSVPushSpec.Builder(AnyTypeKind.USER.name()).
-                ignorePagination(true).
+        CSVPushSpec spec = new CSVPushSpec.Builder(AnyTypeKind.USER.name()).ignorePaging(true).
                 field("username").
                 field("status").
                 plainAttr("firstname").
diff --git a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReconciliationITCase.java b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReconciliationITCase.java
index 5b2a20c..529e09b 100644
--- a/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReconciliationITCase.java
+++ b/fit/core-reference/src/test/java/org/apache/syncope/fit/core/ReconciliationITCase.java
@@ -232,8 +232,7 @@ public class ReconciliationITCase extends AbstractITCase {
                 orderBy("username ASC").
                 build();
 
-        CSVPushSpec spec = new CSVPushSpec.Builder(AnyTypeKind.USER.name()).
-                ignorePagination(true).
+        CSVPushSpec spec = new CSVPushSpec.Builder(AnyTypeKind.USER.name()).ignorePaging(true).
                 field("username").
                 field("status").
                 plainAttr("firstname").