ilgrosso commented on a change in pull request #312:
URL: https://github.com/apache/syncope/pull/312#discussion_r806826486



##########
File path: 
client/console/src/main/java/org/apache/syncope/client/console/commons/ConnectorDataProvider.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.client.console.commons;
+
+import org.apache.syncope.client.console.SyncopeConsoleSession;
+import org.apache.syncope.client.console.pages.BasePage;
+import org.apache.syncope.client.console.rest.ConnectorRestClient;
+import org.apache.syncope.common.lib.to.ConnInstanceTO;
+import org.apache.wicket.PageReference;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder;
+import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
+import org.apache.wicket.model.CompoundPropertyModel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+public class ConnectorDataProvider extends DirectoryDataProvider<Serializable> 
{
+
+    private static final long serialVersionUID = 3122389673525690470L;
+
+    protected static final Logger LOG = 
LoggerFactory.getLogger(ConnectorDataProvider.class);
+
+    private final PageReference pageRef;
+
+    protected int currentPage;
+
+    private String keyword;
+
+    private final ConnectorRestClient restClient = new ConnectorRestClient();
+
+    public ConnectorDataProvider(
+            final int paginatorRows,
+            final PageReference pageRef,
+            final String keyword) {
+        super(paginatorRows);
+        setSort("displayNameSortParam", SortOrder.ASCENDING);
+        this.pageRef = pageRef;
+        this.keyword = keyword;
+    }
+
+    @Override
+    public Iterator<ConnInstanceTO> iterator(final long first, final long 
count) {
+        List<ConnInstanceTO> result = Collections.emptyList();
+
+        try {
+            currentPage = ((int) first / paginatorRows);
+            if (currentPage < 0) {
+                currentPage = 0;
+            }
+            if (keyword == null || keyword.isEmpty()) {
+                result = restClient.getAllConnectors();
+            } else {
+                result = restClient.getAllConnectors().stream().filter(conn ->
+                        
conn.getDisplayName().toLowerCase().contains(keyword)).collect(Collectors.toList());
+            }
+        } catch (Exception e) {
+            LOG.error("While searching", e);
+            SyncopeConsoleSession.get().onException(e);
+
+            Optional<AjaxRequestTarget> target = 
RequestCycle.get().find(AjaxRequestTarget.class);
+            target.ifPresent(ajaxRequestTarget ->
+                    ((BasePage) 
pageRef.getPage()).getNotificationPanel().refresh(ajaxRequestTarget));
+        }
+
+        SortParam<String> sortParam = getSort();
+        if (sortParam != null) {
+            result.sort(getComparator(sortParam));
+        }
+
+        return result.subList((int) first, (int) first + (int) 
count).iterator();
+    }
+
+    private Comparator<ConnInstanceTO> getComparator(final SortParam<String> 
sortParam) {
+        Comparator<ConnInstanceTO> comparator;
+
+        switch (sortParam.getProperty()) {
+            case "displayNameSortParam":
+                comparator = Comparator.nullsFirst(Comparator.comparing(
+                        item -> item.getDisplayName().toLowerCase()));
+                break;
+            case "connectorNameSortParam":
+                comparator = Comparator.nullsFirst(Comparator.comparing(
+                        item -> item.getConnectorName().toLowerCase()));
+                break;
+            default:
+                throw new IllegalStateException("The sort param " + 
sortParam.getProperty() + " is not correct");
+        }
+
+        if (!sortParam.isAscending()) {
+            comparator = comparator.reversed();
+        }
+
+        return comparator;
+    }
+
+    @Override
+    public long size() {
+        long result = 0;
+
+        try {
+            if (keyword == null || keyword.isEmpty()) {

Review comment:
       Use `StringUtils#isBlank` instead

##########
File path: 
client/console/src/main/java/org/apache/syncope/client/console/commons/ResourceDataProvider.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.client.console.commons;
+
+import org.apache.syncope.client.console.SyncopeConsoleSession;
+import org.apache.syncope.client.console.pages.BasePage;
+import org.apache.syncope.client.console.rest.ResourceRestClient;
+import org.apache.syncope.common.lib.to.ResourceTO;
+import org.apache.wicket.PageReference;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder;
+import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
+import org.apache.wicket.model.CompoundPropertyModel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+public class ResourceDataProvider extends DirectoryDataProvider<Serializable> {
+
+    private static final long serialVersionUID = 3189980210236051840L;
+
+    protected static final Logger LOG = 
LoggerFactory.getLogger(ResourceDataProvider.class);
+
+    private final PageReference pageRef;
+
+    protected int currentPage;
+
+    private String keyword;
+
+    private final ResourceRestClient restClient = new ResourceRestClient();
+
+    public ResourceDataProvider(
+            final int paginatorRows,
+            final PageReference pageRef,
+            final String keyword) {
+        super(paginatorRows);
+        setSort("keySortParam", SortOrder.ASCENDING);
+        this.pageRef = pageRef;
+        this.keyword = keyword;
+    }
+
+    @Override
+    public Iterator<ResourceTO> iterator(final long first, final long count) {
+        List<ResourceTO> result = Collections.emptyList();
+
+        try {
+            currentPage = ((int) first / paginatorRows);
+            if (currentPage < 0) {
+                currentPage = 0;
+            }
+            if (keyword == null || keyword.isEmpty()) {

Review comment:
       Use `StringUtils#isBlank` instead

##########
File path: 
client/console/src/main/java/org/apache/syncope/client/console/panels/ConnectorDirectoryPanel.java
##########
@@ -0,0 +1,282 @@
+/*
+ * 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.client.console.panels;
+
+import de.agilecoders.wicket.core.markup.html.bootstrap.dialog.Modal;
+import org.apache.syncope.client.console.SyncopeConsoleSession;
+import org.apache.syncope.client.console.audit.AuditHistoryModal;
+import org.apache.syncope.client.console.commons.ConnectorDataProvider;
+import org.apache.syncope.client.console.commons.Constants;
+import org.apache.syncope.client.console.pages.BasePage;
+import org.apache.syncope.client.console.rest.ConnectorRestClient;
+import 
org.apache.syncope.client.console.wicket.markup.html.bootstrap.dialog.BaseModal;
+import org.apache.syncope.client.console.wicket.markup.html.form.ActionLink;
+import org.apache.syncope.client.console.wicket.markup.html.form.ActionsPanel;
+import org.apache.syncope.client.console.wizards.AjaxWizard;
+import org.apache.syncope.client.console.wizards.WizardMgtPanel;
+import 
org.apache.syncope.client.console.wizards.resources.ConnectorWizardBuilder;
+import 
org.apache.syncope.client.console.wizards.resources.ResourceWizardBuilder;
+import org.apache.syncope.common.lib.SyncopeClientException;
+import org.apache.syncope.common.lib.to.ConnInstanceTO;
+import org.apache.syncope.common.lib.to.ResourceTO;
+import org.apache.syncope.common.lib.types.AuditElements;
+import org.apache.syncope.common.lib.types.StandardEntitlement;
+import org.apache.wicket.PageReference;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import 
org.apache.wicket.authroles.authorization.strategies.role.metadata.MetaDataRoleAuthorizationStrategy;
+import org.apache.wicket.event.IEvent;
+import org.apache.wicket.extensions.markup.html.repeater.data.table.IColumn;
+import 
org.apache.wicket.extensions.markup.html.repeater.data.table.PropertyColumn;
+import org.apache.wicket.model.CompoundPropertyModel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.Model;
+import org.apache.wicket.model.ResourceModel;
+import java.io.Serializable;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+public class ConnectorDirectoryPanel extends
+        DirectoryPanel<Serializable, Serializable, ConnectorDataProvider, 
ConnectorRestClient> {
+
+    private static final long serialVersionUID = 2041468935602350821L;
+
+    private String keyword;
+
+    protected ConnectorDirectoryPanel(final String id, final 
ConnectorDirectoryPanel.Builder builder) {
+        super(id, builder);
+
+        if (SyncopeConsoleSession.get().owns("CONNECTOR_CREATE")) {
+            MetaDataRoleAuthorizationStrategy.authorizeAll(addAjaxLink, 
RENDER);
+        } else {
+            MetaDataRoleAuthorizationStrategy.unauthorizeAll(addAjaxLink, 
RENDER);
+        }
+
+        setShowResultPage(false);
+        modal.size(Modal.Size.Large);
+        initResultTable();
+
+        restClient = builder.restClient;
+    }
+
+    @Override
+    public void onEvent(final IEvent<?> event) {
+        if (event.getPayload() instanceof ConnectorSearchEvent) {
+            ConnectorSearchEvent payload = (ConnectorSearchEvent) 
event.getPayload();
+            AjaxRequestTarget target = payload.getTarget();
+            if (payload.getKeyword() != null && 
!payload.getKeyword().isEmpty()) {

Review comment:
       Use `StringUtils#isNotBlank` instead

##########
File path: 
client/console/src/main/java/org/apache/syncope/client/console/commons/ResourceDataProvider.java
##########
@@ -0,0 +1,151 @@
+/*
+ * 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.client.console.commons;
+
+import org.apache.syncope.client.console.SyncopeConsoleSession;
+import org.apache.syncope.client.console.pages.BasePage;
+import org.apache.syncope.client.console.rest.ResourceRestClient;
+import org.apache.syncope.common.lib.to.ResourceTO;
+import org.apache.wicket.PageReference;
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.extensions.markup.html.repeater.data.sort.SortOrder;
+import org.apache.wicket.extensions.markup.html.repeater.util.SortParam;
+import org.apache.wicket.model.CompoundPropertyModel;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.request.cycle.RequestCycle;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+public class ResourceDataProvider extends DirectoryDataProvider<Serializable> {
+
+    private static final long serialVersionUID = 3189980210236051840L;
+
+    protected static final Logger LOG = 
LoggerFactory.getLogger(ResourceDataProvider.class);
+
+    private final PageReference pageRef;
+
+    protected int currentPage;
+
+    private String keyword;
+
+    private final ResourceRestClient restClient = new ResourceRestClient();
+
+    public ResourceDataProvider(
+            final int paginatorRows,
+            final PageReference pageRef,
+            final String keyword) {
+        super(paginatorRows);
+        setSort("keySortParam", SortOrder.ASCENDING);
+        this.pageRef = pageRef;
+        this.keyword = keyword;
+    }
+
+    @Override
+    public Iterator<ResourceTO> iterator(final long first, final long count) {
+        List<ResourceTO> result = Collections.emptyList();
+
+        try {
+            currentPage = ((int) first / paginatorRows);
+            if (currentPage < 0) {
+                currentPage = 0;
+            }
+            if (keyword == null || keyword.isEmpty()) {
+                result = restClient.list();
+            } else {
+                result = restClient.list().stream().filter(resource ->
+                        
resource.getKey().toLowerCase().contains(keyword)).collect(Collectors.toList());
+            }
+        } catch (Exception e) {
+            LOG.error("While searching", e);
+            SyncopeConsoleSession.get().onException(e);
+
+            Optional<AjaxRequestTarget> target = 
RequestCycle.get().find(AjaxRequestTarget.class);
+            target.ifPresent(ajaxRequestTarget ->
+                    ((BasePage) 
pageRef.getPage()).getNotificationPanel().refresh(ajaxRequestTarget));
+        }
+
+        SortParam<String> sortParam = getSort();
+        if (sortParam != null) {
+            result.sort(getComparator(sortParam));
+        }
+
+        return result.subList((int) first, (int) first + (int) 
count).iterator();
+    }
+
+    private Comparator<ResourceTO> getComparator(final SortParam<String> 
sortParam) {
+        Comparator<ResourceTO> comparator;
+
+        switch (sortParam.getProperty()) {
+            case "keySortParam":
+                comparator = Comparator.nullsFirst(Comparator.comparing(
+                        item -> item.getKey().toLowerCase()));
+                break;
+            case "connectorDisplayNameSortParam":
+                comparator = Comparator.nullsFirst(Comparator.comparing(
+                        item -> item.getConnectorDisplayName().toLowerCase()));
+                break;
+            default:
+                throw new IllegalStateException("The sort param " + 
sortParam.getProperty() + " is not correct");
+        }
+
+        if (!sortParam.isAscending()) {
+            comparator = comparator.reversed();
+        }
+
+        return comparator;
+    }
+
+    @Override
+    public long size() {
+        long result = 0;
+
+        try {
+            if (keyword == null || keyword.isEmpty()) {

Review comment:
       Use `StringUtils#isBlank` instead




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: dev-unsubscr...@syncope.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to