package org.orienteer.core.service.impl;

import com.orientechnologies.orient.core.metadata.schema.OClass;
import com.orientechnologies.orient.core.metadata.schema.OProperty;
import com.orientechnologies.orient.core.metadata.security.ORule;
import com.orientechnologies.orient.core.metadata.security.OSecurityUser;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.danekja.java.util.function.serializable.SerializablePredicate;
import org.orienteer.core.CustomAttribute;
import org.orienteer.core.OClassDomain;
import org.orienteer.core.OrienteerWebSession;
import org.orienteer.core.service.IFilterPredicateFactory;

/**
 * Default implementation for {@link IFilterPredicateFactory}
 */
public class DefaultFilterPredicateFactory implements IFilterPredicateFactory {

    @Override
    public SerializablePredicate<OClass> getPredicateByTarget(IModel<Boolean> showAllModel) {
        return (input) -> {
            Boolean showAll = showAllModel.getObject();
            return showAll == null || showAll || OClassDomain.BUSINESS.equals(CustomAttribute.DOMAIN.getValue(input));
        };
    }

    @Override
    public SerializablePredicate<OClass> getPredicateByOperation(int operation) {
        OSecurityUser user = OrienteerWebSession.get().getUser();
        return user != null ? (input) -> user.checkIfAllowed(ORule.ResourceGeneric.CLASS, input.getName(), operation) != null 
        		: (i) -> false;
    }

    @Override
    @SuppressWarnings("unchecked")
    public SerializablePredicate<OClass> getPredicateForClassesView(IModel<Boolean> showAll) {
        return compose(getPredicateByOperation(2), getPredicateByTarget(showAll));
    }

    @Override
    @SuppressWarnings("unchecked")
    public SerializablePredicate<OClass> getPredicateForClassesSearch() {
        return compose(getPredicateByOperation(2), getPredicateByTarget(Model.of(false)));
    }

    @Override
    public SerializablePredicate<OProperty> getPredicateForListProperties() {
        return (prop) -> !CustomAttribute.HIDDEN.getValue(prop, false);
    }

    @Override
    public SerializablePredicate<OProperty> getPredicateForTableProperties() {
        return (prop) -> CustomAttribute.DISPLAYABLE.getValue(prop, true);
    }
}

@@ -2024,16 +2024,25 @@
 op) -%3E !
+(Boolean)
 CustomAt
@@ -2073,15 +2073,8 @@
 prop
-, false
 );%0A 
@@ -2242,14 +2242,8 @@
 prop
-, true
 );%0A 

Fix issue with using default values for attrs Hidden and Displayable