Validates query based on the given entity type, converts query values to the expected type if
necessary.

@param query query
@param entityType entity type
@throws MolgenisValidationException if query is invalid
181658
public void validate(Query<? extends Entity> query, EntityType entityType) {
    query.getRules().forEach(queryRule -> validateQueryRule(queryRule, entityType));
  }
81945
protected boolean isEntityQuery(ODataUri uri, EntityDataModel entityDataModel) {
        return getTargetType(uri, entityDataModel).map(t -> t.getMetaType() == MetaType.ENTITY).orElse(false);
    }
1246373
private void validateQueryResults(String query, N1qlQueryResult result)
    {
        LOGGER.debug("Query output status: " + result.finalSuccess());

        if (!result.finalSuccess())
        {
            StringBuilder errorBuilder = new StringBuilder();
            for (JsonObject obj : result.errors())
            {
                errorBuilder.append(obj.toString());
                errorBuilder.append("\n");
            }
            errorBuilder.deleteCharAt(errorBuilder.length() - 1);
            String errors = errorBuilder.toString();
            LOGGER.error(errors);
            throw new KunderaException("Not able to execute query/statement:" + query + ". More details : " + errors);
        }
    }
987159
public static EntityType checkIsEntityType(Type type) {
        if (!isEntityType(type)) {
            throw new ODataSystemException("An entity type is required, but '" + type.getFullyQualifiedName() +
                    "' is not an entity type: " + type.getMetaType());
        }
        return (EntityType) type;
    }
1020915
protected function validate($query)
    {
        if ($this->client->getIndex() == null) {
            throw new SearchException("Index cannot be null");
        }
        if ($this->client->getType() == null) {
            throw new SearchException("Type cannot be null");
        }
        if ($query == null) {
            throw new SearchException("Query can't be null");
        }
    }
613542
protected void validate(String operationType) throws Exception
	{
		super.validate(operationType);

		MPSBoolean ntpd_status_validator = new MPSBoolean();
		ntpd_status_validator.validate(operationType, ntpd_status, "\"ntpd_status\"");
		
	}
539033
protected void validate(String operationType) throws Exception
	{
		super.validate(operationType);

		MPSString image_name_validator = new MPSString();
		image_name_validator.setConstraintIsReq(MPSConstants.GENERIC_CONSTRAINT, true);
		image_name_validator.setConstraintMaxStrLen(MPSConstants.GENERIC_CONSTRAINT, 128);
		image_name_validator.setConstraintMinStrLen(MPSConstants.GENERIC_CONSTRAINT, 1);
		image_name_validator.validate(operationType, image_name, "\"image_name\"");
		
		MPSString doc_file_validator = new MPSString();
		doc_file_validator.setConstraintMaxStrLen(MPSConstants.GENERIC_CONSTRAINT, 128);
		doc_file_validator.setConstraintMinStrLen(MPSConstants.GENERIC_CONSTRAINT, 1);
		doc_file_validator.validate(operationType, doc_file, "\"doc_file\"");
		
	}
1294476
private void validateNodeType(NodeTypeData nodeType) throws RepositoryException
   {
      if (nodeType == null)
      {
         throw new RepositoryException("NodeType object " + nodeType + " is null");
      }

      if (nodeType.getName() == null)
      {
         throw new RepositoryException("NodeType implementation class " + nodeType.getClass().getName()
            + " is not supported in this method");
      }

      for (InternalQName sname : nodeType.getDeclaredSupertypeNames())
      {
         if (!nodeType.getName().equals(Constants.NT_BASE) && nodeType.getName().equals(sname))
         {
            throw new RepositoryException("Invalid super type name" + sname.getAsString());
         }
      }

      for (PropertyDefinitionData pdef : nodeType.getDeclaredPropertyDefinitions())
      {
         if (!pdef.getDeclaringNodeType().equals(nodeType.getName()))
         {
            throw new RepositoryException("Invalid declared node type in property definitions with name "
               + pdef.getName().getAsString() + " not registred");
         }
         
         // validate default values
         try
         {
            validateValueDefaults(pdef.getRequiredType(), pdef.getDefaultValues());
         }
         catch (ValueFormatException e)
         {
            throw new ValueFormatException("Default value is incompatible with Property type "
               + PropertyType.nameFromValue(pdef.getRequiredType()) + " of " + pdef.getName().getAsString()
               + " in nodetype " + nodeType.getName().getAsString(), e);
         }
         
         try
         {
            validateValueConstraints(pdef.getRequiredType(), pdef.getValueConstraints());
         }
         catch (ValueFormatException e)
         {
            throw new ValueFormatException("Constraints is incompatible with Property type "
               + PropertyType.nameFromValue(pdef.getRequiredType()) + " of " + pdef.getName().getAsString()
               + " in nodetype " + nodeType.getName().getAsString(), e);
         }
      }

      for (NodeDefinitionData cndef : nodeType.getDeclaredChildNodeDefinitions())
      {
         if (!cndef.getDeclaringNodeType().equals(nodeType.getName()))
         {
            throw new RepositoryException("Invalid declared node type in child node definitions with name "
               + cndef.getName().getAsString() + " not registred");
         }
      }
   }
323795
protected void validate(String operationType) throws Exception
	{
		super.validate(operationType);

		MPSString serial_no_validator = new MPSString();
		serial_no_validator.validate(operationType, serial_no, "\"serial_no\"");
		
		MPSString id_validator = new MPSString();
		id_validator.validate(operationType, id, "\"id\"");
		
		MPSString session_id_validator = new MPSString();
		session_id_validator.validate(operationType, session_id, "\"session_id\"");
		
		MPSString name_validator = new MPSString();
		name_validator.validate(operationType, name, "\"name\"");
		
		MPSInt relevance_validator = new MPSInt();
		relevance_validator.validate(operationType, relevance, "\"relevance\"");
		
		MPSString bind_type_validator = new MPSString();
		bind_type_validator.validate(operationType, bind_type, "\"bind_type\"");
		
		MPSInt count_total_validator = new MPSInt();
		count_total_validator.validate(operationType, count_total, "\"count_total\"");
		
		MPSInt count_available_validator = new MPSInt();
		count_available_validator.validate(operationType, count_available, "\"count_available\"");
		
		MPSString date_purchased_validator = new MPSString();
		date_purchased_validator.validate(operationType, date_purchased, "\"date_purchased\"");
		
		MPSString date_exp_validator = new MPSString();
		date_exp_validator.validate(operationType, date_exp, "\"date_exp\"");
		
		MPSString features_validator = new MPSString();
		features_validator.validate(operationType, features, "\"features\"");
		
	}
837690
protected void validate(String operationType) throws Exception
	{
		super.validate(operationType);

		MPSString id_validator = new MPSString();
		id_validator.setConstraintIsReq(MPSConstants.DELETE_CONSTRAINT, true);
		id_validator.setConstraintIsReq(MPSConstants.MODIFY_CONSTRAINT, true);
		id_validator.validate(operationType, id, "\"id\"");
		
		MPSString profile_name_validator = new MPSString();
		profile_name_validator.setConstraintMaxStrLen(MPSConstants.GENERIC_CONSTRAINT, 128);
		profile_name_validator.setConstraintMinStrLen(MPSConstants.GENERIC_CONSTRAINT, 1);
		profile_name_validator.setConstraintIsReq(MPSConstants.ADD_CONSTRAINT, true);
		profile_name_validator.validate(operationType, profile_name, "\"profile_name\"");
		
		MPSInternetHost server_name_validator = new MPSInternetHost();
		server_name_validator.setConstraintIsReq(MPSConstants.ADD_CONSTRAINT, true);
		server_name_validator.validate(operationType, server_name, "\"server_name\"");
		
		MPSString to_list_validator = new MPSString();
		to_list_validator.setConstraintMinStrLen(MPSConstants.GENERIC_CONSTRAINT, 6);
		to_list_validator.validate(operationType, to_list, "\"to_list\"");
		
		MPSString cc_list_validator = new MPSString();
		cc_list_validator.validate(operationType, cc_list, "\"cc_list\"");
		
		MPSString bcc_list_validator = new MPSString();
		bcc_list_validator.validate(operationType, bcc_list, "\"bcc_list\"");
		
	}
882764
protected void validate(String operationType) throws Exception
	{
		super.validate(operationType);

		MPSString id_validator = new MPSString();
		id_validator.validate(operationType, id, "\"id\"");
		
		MPSInt vpn_license_in_use_validator = new MPSInt();
		vpn_license_in_use_validator.validate(operationType, vpn_license_in_use, "\"vpn_license_in_use\"");
		
		MPSIPAddress ns_ip_address_validator = new MPSIPAddress();
		ns_ip_address_validator.validate(operationType, ns_ip_address, "\"ns_ip_address\"");
		
	}
758225
public static void checkQuery(SpiQuery<?> query, ListExpressionValidation validation, boolean ignoreUnknown) {
        if (query != null) {
            validate(query.getWhereExpressions(), validation, ignoreUnknown);
            validate(query.getHavingExpressions(), validation, ignoreUnknown);
            validate(query.getOrderBy(), validation, ignoreUnknown);

            Set<String> invalid = validation.getUnknownProperties();

            if (!ignoreUnknown && !invalid.isEmpty()) {
                UnprocessableEntityException.throwQuery(invalid);
            }
        }
    }
24281
protected void validate(String operationType) throws Exception
	{
		super.validate(operationType);

		MPSString name_validator = new MPSString();
		name_validator.setConstraintIsReq(MPSConstants.DELETE_CONSTRAINT, true);
		name_validator.setConstraintCharSetRegEx(MPSConstants.GENERIC_CONSTRAINT,"[ a-zA-Z0-9_#.:@=-]+");
		name_validator.setConstraintMaxStrLen(MPSConstants.GENERIC_CONSTRAINT, 32);
		name_validator.setConstraintMinStrLen(MPSConstants.GENERIC_CONSTRAINT, 1);
		name_validator.setConstraintIsReq(MPSConstants.ADD_CONSTRAINT, true);
		name_validator.setConstraintIsReq(MPSConstants.MODIFY_CONSTRAINT, true);
		name_validator.validate(operationType, name, "\"name\"");
		
		MPSString subtree_validator = new MPSString();
		subtree_validator.setConstraintCharSetRegEx(MPSConstants.GENERIC_CONSTRAINT,"[ a-zA-Z0-9_#.:@=-]+");
		subtree_validator.setConstraintMaxStrLen(MPSConstants.GENERIC_CONSTRAINT, 256);
		subtree_validator.setConstraintMinStrLen(MPSConstants.GENERIC_CONSTRAINT, 1);
		subtree_validator.validate(operationType, subtree, "\"subtree\"");
		
		MPSBoolean type_validator = new MPSBoolean();
		type_validator.validate(operationType, type, "\"type\"");
		
		MPSString type_str_validator = new MPSString();
		type_str_validator.validate(operationType, type_str, "\"type_str\"");
		
	}
215249
private void validateExternalCallback(Method method, CallbackType callbackType) {
    Class<?>[] parameters = method.getParameterTypes();
    if (!parameters[0].isAssignableFrom(entityClass)) {
      String message = String.format("Method %s in class %s is not valid for entity %s",
          method.getName(), method.getDeclaringClass().getName(), entityClass.getName());
      throw new EntityManagerException(message);
    }
    CallbackMetadata callbackMetadata = new CallbackMetadata(EntityListenerType.EXTERNAL,
        callbackType, method);
    metadata.put(callbackType, callbackMetadata);
  }
671914
private void validateSelectQuery(final String selectQuery) {
        final SimpleDBParser parser = new SimpleDBParser(selectQuery);
        try {
            parser.selectQuery();
        } catch (Exception e) {
            throw new InvalidSimpleDBQueryException("The following query is an invalid SimpleDB query: " + selectQuery,
                    e);
        }
    }
882938
protected void validate(String operationType) throws Exception
	{
		super.validate(operationType);

		MPSString name_validator = new MPSString();
		name_validator.setConstraintCharSetRegEx(MPSConstants.GENERIC_CONSTRAINT,"[a-zA-Z0-9_#.:@=-]+");
		name_validator.setConstraintMaxStrLen(MPSConstants.GENERIC_CONSTRAINT, 128);
		name_validator.setConstraintMinStrLen(MPSConstants.GENERIC_CONSTRAINT, 1);
		name_validator.validate(operationType, name, "\"name\"");
		
		MPSIPAddress ip_address_validator = new MPSIPAddress();
		ip_address_validator.validate(operationType, ip_address, "\"ip_address\"");
		
		MPSInt port_validator = new MPSInt();
		port_validator.setConstraintMaxValue(MPSConstants.GENERIC_CONSTRAINT, 65535);
		port_validator.validate(operationType, port, "\"port\"");
		
		MPSBoolean log_level_all_validator = new MPSBoolean();
		log_level_all_validator.validate(operationType, log_level_all, "\"log_level_all\"");
		
		MPSBoolean log_level_none_validator = new MPSBoolean();
		log_level_none_validator.validate(operationType, log_level_none, "\"log_level_none\"");
		
		MPSBoolean log_level_emergency_validator = new MPSBoolean();
		log_level_emergency_validator.validate(operationType, log_level_emergency, "\"log_level_emergency\"");
		
		MPSBoolean log_level_alert_validator = new MPSBoolean();
		log_level_alert_validator.validate(operationType, log_level_alert, "\"log_level_alert\"");
		
		MPSBoolean log_level_critical_validator = new MPSBoolean();
		log_level_critical_validator.validate(operationType, log_level_critical, "\"log_level_critical\"");
		
		MPSBoolean log_level_error_validator = new MPSBoolean();
		log_level_error_validator.validate(operationType, log_level_error, "\"log_level_error\"");
		
		MPSBoolean log_level_warning_validator = new MPSBoolean();
		log_level_warning_validator.validate(operationType, log_level_warning, "\"log_level_warning\"");
		
		MPSBoolean log_level_notice_validator = new MPSBoolean();
		log_level_notice_validator.validate(operationType, log_level_notice, "\"log_level_notice\"");
		
		MPSBoolean log_level_info_validator = new MPSBoolean();
		log_level_info_validator.validate(operationType, log_level_info, "\"log_level_info\"");
		
		MPSBoolean log_level_debug_validator = new MPSBoolean();
		log_level_debug_validator.validate(operationType, log_level_debug, "\"log_level_debug\"");
		
		MPSString log_levels_validator = new MPSString();
		log_levels_validator.validate(operationType, log_levels, "\"log_levels\"");
		
	}
1190837
static void validateEntityLabel(EntityType entityType) {
    String label = entityType.getLabel();
    if (label != null) {
      if (label.isEmpty()) {
        throw new MolgenisValidationException(
            new ConstraintViolation(
                format("Label of EntityType [%s] is empty", entityType.getId())));
      } else if (label.trim().equals("")) {
        throw new MolgenisValidationException(
            new ConstraintViolation(
                format("Label of EntityType [%s] contains only white space", entityType.getId())));
      }
    }
  }