cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1497774 - in /cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search: jpa/ ldap/ lucene/ sql/ visitor/
Date Fri, 28 Jun 2013 13:51:10 GMT
Author: sergeyb
Date: Fri Jun 28 13:51:10 2013
New Revision: 1497774

URL: http://svn.apache.org/r1497774
Log:
[CXF-5101] More options to get the parsed values validated

Added:
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/PropertyValidationException.java
  (with props)
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/PropertyValidator.java
  (with props)
Modified:
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/ldap/LdapQueryVisitor.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
    cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractUntypedSearchConditionVisitor.java

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java?rev=1497774&r1=1497773&r2=1497774&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/jpa/AbstractJPATypedQueryVisitor.java
Fri Jun 28 13:51:10 2013
@@ -164,12 +164,15 @@ public abstract class AbstractJPATypedQu
     
     private Predicate buildPredicate(PrimitiveStatement ps) {
         String name = ps.getProperty();
+        Object propertyValue = ps.getValue();
+        validatePropertyValue(name, propertyValue);
+        
         name = super.getRealPropertyName(name);
         ClassValue cv = getPrimitiveFieldClass(ps,
                                                name, 
                                                ps.getValue().getClass(), 
                                                ps.getValueType(), 
-                                               ps.getValue()); 
+                                               propertyValue); 
         CollectionCheckInfo collInfo = cv.getCollectionCheckInfo();
         Path<?> path = getPath(root, name, cv, collInfo);
         

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/ldap/LdapQueryVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/ldap/LdapQueryVisitor.java?rev=1497774&r1=1497773&r2=1497774&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/ldap/LdapQueryVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/ldap/LdapQueryVisitor.java
Fri Jun 28 13:51:10 2013
@@ -48,9 +48,10 @@ public class LdapQueryVisitor<T> extends
         PrimitiveStatement statement = sc.getStatement();
         if (statement != null) {
             if (statement.getProperty() != null) {
-                String rvalStr = statement.getValue().toString();
                 String name = getRealPropertyName(statement.getProperty());
-               
+                String rvalStr = getPropertyValue(name, statement.getValue());
+                validatePropertyValue(name, rvalStr);
+                
                 sb.append("(");
                 if (sc.getConditionType() == ConditionType.NOT_EQUALS) {
                     sb.append("!");

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java?rev=1497774&r1=1497773&r2=1497774&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/lucene/LuceneQueryVisitor.java
Fri Jun 28 13:51:10 2013
@@ -102,6 +102,8 @@ public class LuceneQueryVisitor<T> exten
     
     private Query buildSimpleQuery(ConditionType ct, String name, Object value) {
         name = super.getRealPropertyName(name);
+        validatePropertyValue(name, value);
+        
         Class<?> clazz = getPrimitiveFieldClass(name, value.getClass());
         
         

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java?rev=1497774&r1=1497773&r2=1497774&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/sql/SQLPrinterVisitor.java
Fri Jun 28 13:51:10 2013
@@ -67,9 +67,12 @@ public class SQLPrinterVisitor<T> extend
         PrimitiveStatement statement = sc.getStatement();
         if (statement != null) {
             if (statement.getProperty() != null) {
-                String rvalStr = statement.getValue().toString().replaceAll("\\*", "%");
                 String name = getRealPropertyName(statement.getProperty());
-               
+                String value = getPropertyValue(name, statement.getValue());
+                validatePropertyValue(name, value);
+                String rvalStr = value.replaceAll("\\*", "%");
+                
+                                
                 if (tableAlias != null) {
                     name = tableAlias + "." + name;
                 }

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java?rev=1497774&r1=1497773&r2=1497774&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractSearchConditionVisitor.java
Fri Jun 28 13:51:10 2013
@@ -36,6 +36,7 @@ public abstract class AbstractSearchCond
     
     private Map<String, String> fieldMap;
     private Map<String, Class<?>> primitiveFieldTypeMap;
+    private PropertyValidator<Object> validator;
     
     protected AbstractSearchConditionVisitor(Map<String, String> fieldMap) {
         this.fieldMap = fieldMap;
@@ -158,4 +159,14 @@ public abstract class AbstractSearchCond
             return collectionProps != null && collectionProps.contains(name);
         }
     }
+    
+    protected void validatePropertyValue(String name, Object value) {
+        if (validator != null) {
+            validator.validate(name, value);
+        }
+    }
+    
+    public void setValidator(PropertyValidator<Object> validator) {
+        this.validator = validator;
+    }
 }

Modified: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractUntypedSearchConditionVisitor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractUntypedSearchConditionVisitor.java?rev=1497774&r1=1497773&r2=1497774&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractUntypedSearchConditionVisitor.java
(original)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/AbstractUntypedSearchConditionVisitor.java
Fri Jun 28 13:51:10 2013
@@ -35,6 +35,10 @@ public abstract class AbstractUntypedSea
     public VisitorState<StringBuilder> getVisitorState() {
         return this.state;
     }
+
+    protected String getPropertyValue(String name, Object value) {
+        return value.toString();
+    }
     
     protected StringBuilder getStringBuilder() {
         return getVisitorState().get();
@@ -52,5 +56,4 @@ public abstract class AbstractUntypedSea
         StringBuilder sb = removeStringBuilder();
         return sb == null ? null : sb.toString();
     }
-    
 }

Added: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/PropertyValidationException.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/PropertyValidationException.java?rev=1497774&view=auto
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/PropertyValidationException.java
(added)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/PropertyValidationException.java
Fri Jun 28 13:51:10 2013
@@ -0,0 +1,35 @@
+/**
+ * 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.cxf.jaxrs.ext.search.visitor;
+
+public class PropertyValidationException extends RuntimeException {
+    private static final long serialVersionUID = -3262559013167020058L;
+    private String name;
+    private String value;
+    public PropertyValidationException(String name, String value) {
+        this.name = name;
+        this.value = value;
+    }
+    public String getName() {
+        return name;
+    }
+    public String getValue() {
+        return value;
+    }
+}

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/PropertyValidationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/PropertyValidationException.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/PropertyValidator.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/PropertyValidator.java?rev=1497774&view=auto
==============================================================================
--- cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/PropertyValidator.java
(added)
+++ cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/PropertyValidator.java
Fri Jun 28 13:51:10 2013
@@ -0,0 +1,24 @@
+/**
+ * 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.cxf.jaxrs.ext.search.visitor;
+
+
+public interface PropertyValidator<T> {
+    void validate(String name, T value) throws PropertyValidationException;
+}

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/PropertyValidator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cxf/trunk/rt/rs/extensions/search/src/main/java/org/apache/cxf/jaxrs/ext/search/visitor/PropertyValidator.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date



Mime
View raw message