All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.knightsoftnet.gwtp.spring.shared.search._SearchRequestValidatorImpl Maven / Gradle / Ivy

Go to download

A set of widgets and handlers using server calls for gwt applications using gwt-bean-validators-spring-gwtp.

There is a newer version: 2.3.2
Show newest version
package de.knightsoftnet.gwtp.spring.shared.search;

import de.knightsoftnet.validators.client.impl.AbstractGwtSpecificValidator;
import de.knightsoftnet.validators.client.impl.ConstraintDescriptorImpl;
import de.knightsoftnet.validators.client.impl.Group;
import de.knightsoftnet.validators.client.impl.GroupChain;
import de.knightsoftnet.validators.client.impl.GroupChainGenerator;
import de.knightsoftnet.validators.client.impl.GwtBeanDescriptor;
import de.knightsoftnet.validators.client.impl.GwtBeanDescriptorImpl;
import de.knightsoftnet.validators.client.impl.GwtValidationContext;
import de.knightsoftnet.validators.client.impl.metadata.BeanMetadata;
import de.knightsoftnet.validators.client.impl.metadata.ValidationGroupsMetadata;
import de.knightsoftnet.validators.client.impl.PropertyDescriptorImpl;

import org.hibernate.validator.internal.engine.path.PathImpl;

import java.lang.annotation.Annotation;
import java.lang.IllegalArgumentException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import jakarta.validation.ConstraintViolation;
import jakarta.validation.Path.Node;
import jakarta.validation.ValidationException;

public class _SearchRequestValidatorImpl
    extends AbstractGwtSpecificValidator
    implements _SearchRequestValidator {
  private static final java.util.List ALL_PROPERTY_NAMES = 
      java.util.Collections.unmodifiableList(
          java.util.Arrays.asList("searchCriterias","class"));
  private final BeanMetadata beanMetadata =
      new BeanMetadata(
          de.knightsoftnet.gwtp.spring.shared.search.SearchRequest.class,
          jakarta.validation.groups.Default.class);

  private final GwtBeanDescriptor beanDescriptor = 
      (GwtBeanDescriptorImpl) GwtBeanDescriptorImpl.builder(de.knightsoftnet.gwtp.spring.shared.search.SearchRequest.class)
          .setConstrained(false)
          .setBeanMetadata(beanMetadata)
          .build();


  public  void validateClassGroups(
      final GwtValidationContext context,
      final de.knightsoftnet.gwtp.spring.shared.search.SearchRequest object,
      final Set> violations,
      final Class... groups) {
    validateAllNonInheritedProperties(context, object, violations, groups);
  }

  public  void expandDefaultAndValidateClassGroups(
      final GwtValidationContext context,
      final de.knightsoftnet.gwtp.spring.shared.search.SearchRequest object,
      final Set> violations,
      final Group... groups) {
    final ArrayList> justGroups = new ArrayList<>();
    for (Group g : groups) {
      if (!g.isDefaultGroup() || !getBeanMetadata().defaultGroupSequenceIsRedefined()) {
        justGroups.add(g.getGroup());
      }
    }
    final Class[] justGroupsArray = justGroups.toArray(new Class[justGroups.size()]);
    validateAllNonInheritedProperties(context, object, violations, justGroupsArray);
    if (getBeanMetadata().defaultGroupSequenceIsRedefined()) {
      for (Class g : beanMetadata.getDefaultGroupSequence()) {
        int numberOfViolations = violations.size();
        validateAllNonInheritedProperties(context, object, violations, g);
        if (violations.size() > numberOfViolations) {
          break;
        }
      }
    }
  }

  public  void expandDefaultAndValidatePropertyGroups(
      final GwtValidationContext context,
      final de.knightsoftnet.gwtp.spring.shared.search.SearchRequest object,
      final String propertyName,
      final Set> violations,
      final Group... groups) {
    final ArrayList> justGroups = new ArrayList<>();
    for (Group g : groups) {
      if (!g.isDefaultGroup() || !getBeanMetadata().defaultGroupSequenceIsRedefined()) {
        justGroups.add(g.getGroup());
      }
    }
    final Class[] justGroupsArray = justGroups.toArray(new Class[justGroups.size()]);
    validatePropertyGroups(context, object, propertyName, violations, justGroupsArray);
    if (getBeanMetadata().defaultGroupSequenceIsRedefined()) {
      for (Class g : beanMetadata.getDefaultGroupSequence()) {
        int numberOfViolations = violations.size();
        validatePropertyGroups(context, object, propertyName, violations, g);
        if (violations.size() > numberOfViolations) {
          break;
        }
      }
    }
  }

  public  void expandDefaultAndValidateValueGroups(
      final GwtValidationContext context,
      final Class beanType,
      final String propertyName,
      final Object value,
      final Set> violations,
      final Group... groups) {
    final ArrayList> justGroups = new ArrayList<>();
    for (Group g : groups) {
      if (!g.isDefaultGroup() || !getBeanMetadata().defaultGroupSequenceIsRedefined()) {
        justGroups.add(g.getGroup());
      }
    }
    final Class[] justGroupsArray = justGroups.toArray(new Class[justGroups.size()]);
    validateValueGroups(context, beanType, propertyName, value, violations, justGroupsArray);
    if (getBeanMetadata().defaultGroupSequenceIsRedefined()) {
      for (Class g : beanMetadata.getDefaultGroupSequence()) {
        int numberOfViolations = violations.size();
        validateValueGroups(context, beanType, propertyName, value, violations, g);
        if (violations.size() > numberOfViolations) {
          break;
        }
      }
    }
  }

  public  void validatePropertyGroups(
      final GwtValidationContext context,
      final de.knightsoftnet.gwtp.spring.shared.search.SearchRequest object,
      final String propertyName,
      final Set> violations,
      final Class... groups) throws ValidationException {
    switch (propertyName) {
      default:
        if (!ALL_PROPERTY_NAMES.contains(propertyName)) {
          throw new IllegalArgumentException(propertyName + " is not a valid property of "
              + "de.knightsoftnet.gwtp.spring.shared.search.SearchRequest");
        }
        break;
    }
  }

  public  void validateValueGroups(
      final GwtValidationContext context,
      final Class beanType,
      final String propertyName,
      final Object value,
      final Set> violations,
      final Class... groups) {
    switch (propertyName) {
      default:
        if (!ALL_PROPERTY_NAMES.contains(propertyName)) {
          throw new IllegalArgumentException(propertyName + " is not a valid property of "
              + "de.knightsoftnet.gwtp.spring.shared.search.SearchRequest");
        }
        break;
    }
  }

  public BeanMetadata getBeanMetadata() {
    return beanMetadata;
  }

  public GwtBeanDescriptor getConstraints(
      final ValidationGroupsMetadata validationGroupsMetadata) {
    beanDescriptor.setValidationGroupsMetadata(validationGroupsMetadata);
    return beanDescriptor;
  }


  private  void validateAllNonInheritedProperties(
      final GwtValidationContext context,
      final de.knightsoftnet.gwtp.spring.shared.search.SearchRequest object,
      final Set> violations,
      final Class... groups) {
  }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy