Small fixes
authorFrancesco Chicchiriccò <ilgrosso@apache.org>
Thu, 31 May 2018 06:56:48 +0000 (08:56 +0200)
committerFrancesco Chicchiriccò <ilgrosso@apache.org>
Thu, 31 May 2018 06:56:48 +0000 (08:56 +0200)
client/console/src/main/java/org/apache/syncope/client/console/wicket/extensions/markup/html/repeater/data/table/AttrColumn.java
core/logic/src/main/java/org/apache/syncope/core/logic/SchemaLogic.java

index d562805..0aa49fd 100644 (file)
@@ -18,8 +18,8 @@
  */
 package org.apache.syncope.client.console.wicket.extensions.markup.html.repeater.data.table;
 
+import java.util.ArrayList;
 import java.util.List;
-import org.apache.syncope.common.lib.to.AttrTO;
 import org.apache.syncope.common.lib.types.SchemaType;
 import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
 import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
@@ -49,29 +49,25 @@ public class AttrColumn<T extends AttributableTO> extends AbstractColumn<T, Stri
     public void populateItem(
             final Item<ICellPopulator<T>> cellItem, final String componentId, final IModel<T> rowModel) {
 
-        List<String> values = null;
+        List<String> values = new ArrayList<>();
 
-        AttrTO attr = null;
         switch (schemaType) {
             case PLAIN:
-                attr = rowModel.getObject().getPlainAttr(name).get();
+                rowModel.getObject().getPlainAttr(name).ifPresent(attr -> values.addAll(attr.getValues()));
                 break;
 
             case DERIVED:
-                attr = rowModel.getObject().getDerAttr(name).get();
+                rowModel.getObject().getDerAttr(name).ifPresent(attr -> values.addAll(attr.getValues()));
                 break;
 
             case VIRTUAL:
-                attr = rowModel.getObject().getVirAttr(name).get();
+                rowModel.getObject().getVirAttr(name).ifPresent(attr -> values.addAll(attr.getValues()));
                 break;
 
             default:
         }
-        if (attr != null) {
-            values = attr.getValues();
-        }
 
-        if (values == null || values.isEmpty()) {
+        if (values.isEmpty()) {
             cellItem.add(new Label(componentId, ""));
         } else if (values.size() == 1) {
             cellItem.add(new Label(componentId, values.get(0)));
index b87d3d6..34b7d08 100644 (file)
@@ -21,7 +21,6 @@ package org.apache.syncope.core.logic;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
-import java.util.function.Function;
 import java.util.stream.Collectors;
 import org.apache.commons.lang3.ArrayUtils;
 import org.apache.commons.lang3.StringUtils;
@@ -147,6 +146,7 @@ public class SchemaLogic extends AbstractTransactionalLogic<SchemaTO> {
 
     @PreAuthorize("isAuthenticated()")
     @Transactional(readOnly = true)
+    @SuppressWarnings("unchecked")
     public <T extends SchemaTO> List<T> search(
             final SchemaType schemaType, final List<String> anyTypeClasses, final String keyword) {
 
@@ -171,14 +171,8 @@ public class SchemaLogic extends AbstractTransactionalLogic<SchemaTO> {
                         ? keyword == null
                                 ? virSchemaDAO.findAll()
                                 : virSchemaDAO.findByKeyword(keyword)
-                        : virSchemaDAO.findByAnyTypeClasses(classes)).
-                        stream().map(new Function<VirSchema, T>() {
-
-                            @Override
-                            public T apply(final VirSchema schema) {
-                                return (T) binder.getVirSchemaTO(schema);
-                            }
-                        }).collect(Collectors.toList());
+                        : virSchemaDAO.findByAnyTypeClasses(classes)).stream().
+                        map(schema -> (T) binder.getVirSchemaTO(schema)).collect(Collectors.toList());
                 break;
 
             case DERIVED:
@@ -186,14 +180,8 @@ public class SchemaLogic extends AbstractTransactionalLogic<SchemaTO> {
                         ? keyword == null
                                 ? derSchemaDAO.findAll()
                                 : derSchemaDAO.findByKeyword(keyword)
-                        : derSchemaDAO.findByAnyTypeClasses(classes)).
-                        stream().map(new Function<DerSchema, T>() {
-
-                            @Override
-                            public T apply(final DerSchema schema) {
-                                return (T) binder.getDerSchemaTO(schema);
-                            }
-                        }).collect(Collectors.toList());
+                        : derSchemaDAO.findByAnyTypeClasses(classes)).stream().
+                        map(schema -> (T) binder.getDerSchemaTO(schema)).collect(Collectors.toList());
                 break;
 
             case PLAIN:
@@ -202,14 +190,8 @@ public class SchemaLogic extends AbstractTransactionalLogic<SchemaTO> {
                         ? keyword == null
                                 ? plainSchemaDAO.findAll()
                                 : plainSchemaDAO.findByKeyword(keyword)
-                        : plainSchemaDAO.findByAnyTypeClasses(classes)).
-                        stream().map(new Function<PlainSchema, T>() {
-
-                            @Override
-                            public T apply(final PlainSchema schema) {
-                                return (T) binder.getPlainSchemaTO(schema);
-                            }
-                        }).collect(Collectors.toList());
+                        : plainSchemaDAO.findByAnyTypeClasses(classes)).stream().
+                        map(schema -> (T) binder.getPlainSchemaTO(schema)).collect(Collectors.toList());
         }
 
         return result;