Search in sources :

Example 6 with MissingPropertyException

use of groovy.lang.MissingPropertyException in project grails-core by grails.

the class ConstrainedProperty method setMin.

/**
     * @param min The min to set.
     */
@SuppressWarnings("rawtypes")
public void setMin(Comparable min) {
    if (min == null) {
        appliedConstraints.remove(MIN_CONSTRAINT);
        return;
    }
    if (!propertyType.equals(min.getClass())) {
        throw new MissingPropertyException(MIN_CONSTRAINT, propertyType);
    }
    Range r = getRange();
    if (r != null) {
        LOG.warn("Range constraint already set ignoring constraint [" + MIN_CONSTRAINT + "] for value [" + min + "]");
        return;
    }
    Constraint c = appliedConstraints.get(MIN_CONSTRAINT);
    if (c == null) {
        c = new MinConstraint();
        c.setOwningClass(owningClass);
        c.setPropertyName(propertyName);
        appliedConstraints.put(MIN_CONSTRAINT, c);
    }
    c.setParameter(min);
}
Also used : MaxSizeConstraint(org.grails.validation.MaxSizeConstraint) MinConstraint(org.grails.validation.MinConstraint) SizeConstraint(org.grails.validation.SizeConstraint) MinSizeConstraint(org.grails.validation.MinSizeConstraint) BlankConstraint(org.grails.validation.BlankConstraint) RangeConstraint(org.grails.validation.RangeConstraint) ValidatorConstraint(org.grails.validation.ValidatorConstraint) ScaleConstraint(org.grails.validation.ScaleConstraint) NullableConstraint(org.grails.validation.NullableConstraint) MaxConstraint(org.grails.validation.MaxConstraint) CreditCardConstraint(org.grails.validation.CreditCardConstraint) UrlConstraint(org.grails.validation.UrlConstraint) InListConstraint(org.grails.validation.InListConstraint) MatchesConstraint(org.grails.validation.MatchesConstraint) NotEqualConstraint(org.grails.validation.NotEqualConstraint) EmailConstraint(org.grails.validation.EmailConstraint) MissingPropertyException(groovy.lang.MissingPropertyException) Range(groovy.lang.Range) MinConstraint(org.grails.validation.MinConstraint)

Example 7 with MissingPropertyException

use of groovy.lang.MissingPropertyException in project grails-core by grails.

the class ConstrainedProperty method setMax.

/**
     * @param max The max to set.
     */
@SuppressWarnings("rawtypes")
public void setMax(Comparable max) {
    if (max == null) {
        appliedConstraints.remove(MAX_CONSTRAINT);
        return;
    }
    if (!propertyType.equals(max.getClass())) {
        throw new MissingPropertyException(MAX_CONSTRAINT, propertyType);
    }
    Range r = getRange();
    if (r != null) {
        LOG.warn("Range constraint already set ignoring constraint [" + MAX_CONSTRAINT + "] for value [" + max + "]");
        return;
    }
    Constraint c = appliedConstraints.get(MAX_CONSTRAINT);
    if (c == null) {
        c = new MaxConstraint();
        c.setOwningClass(owningClass);
        c.setPropertyName(propertyName);
        appliedConstraints.put(MAX_CONSTRAINT, c);
    }
    c.setParameter(max);
}
Also used : MaxConstraint(org.grails.validation.MaxConstraint) MaxSizeConstraint(org.grails.validation.MaxSizeConstraint) MinConstraint(org.grails.validation.MinConstraint) SizeConstraint(org.grails.validation.SizeConstraint) MinSizeConstraint(org.grails.validation.MinSizeConstraint) BlankConstraint(org.grails.validation.BlankConstraint) RangeConstraint(org.grails.validation.RangeConstraint) ValidatorConstraint(org.grails.validation.ValidatorConstraint) ScaleConstraint(org.grails.validation.ScaleConstraint) NullableConstraint(org.grails.validation.NullableConstraint) MaxConstraint(org.grails.validation.MaxConstraint) CreditCardConstraint(org.grails.validation.CreditCardConstraint) UrlConstraint(org.grails.validation.UrlConstraint) InListConstraint(org.grails.validation.InListConstraint) MatchesConstraint(org.grails.validation.MatchesConstraint) NotEqualConstraint(org.grails.validation.NotEqualConstraint) EmailConstraint(org.grails.validation.EmailConstraint) MissingPropertyException(groovy.lang.MissingPropertyException) Range(groovy.lang.Range)

Example 8 with MissingPropertyException

use of groovy.lang.MissingPropertyException in project groovy-core by groovy.

the class GroovyResultSetExtension method setProperty.

/**
     * Updates the designated column with an <code>Object</code> value.
     *
     * @param columnName the SQL name of the column
     * @param newValue   the updated value
     * @throws MissingPropertyException if an SQLException happens while setting the new value
     * @see groovy.lang.GroovyObject#setProperty(java.lang.String, java.lang.Object)
     * @see ResultSet#updateObject(java.lang.String, java.lang.Object)
     */
public void setProperty(String columnName, Object newValue) {
    try {
        getResultSet().updateObject(columnName, newValue);
        updated = true;
    } catch (SQLException e) {
        throw new MissingPropertyException(columnName, GroovyResultSetProxy.class, e);
    }
}
Also used : SQLException(java.sql.SQLException) MissingPropertyException(groovy.lang.MissingPropertyException)

Example 9 with MissingPropertyException

use of groovy.lang.MissingPropertyException in project groovy-core by groovy.

the class GroovyRowResult method getAt.

/**
     * Retrieve the value of the property by its index.
     * A negative index will count backwards from the last column.
     *
     * @param index is the number of the column to look at
     * @return the value of the property
     */
public Object getAt(int index) {
    try {
        // a negative index will count backwards from the last column.
        if (index < 0)
            index += result.size();
        Iterator it = result.values().iterator();
        int i = 0;
        Object obj = null;
        while ((obj == null) && (it.hasNext())) {
            if (i == index)
                obj = it.next();
            else
                it.next();
            i++;
        }
        return obj;
    } catch (Exception e) {
        throw new MissingPropertyException(Integer.toString(index), GroovyRowResult.class, e);
    }
}
Also used : Iterator(java.util.Iterator) MissingPropertyException(groovy.lang.MissingPropertyException) MissingPropertyException(groovy.lang.MissingPropertyException)

Example 10 with MissingPropertyException

use of groovy.lang.MissingPropertyException in project webpieces by deanhiller.

the class ProxyResponse method sendRenderHtml.

@Override
public CompletableFuture<Void> sendRenderHtml(RenderResponse resp) {
    log.info(() -> "Sending render html response. req=" + request);
    View view = resp.view;
    String packageStr = view.getPackageName();
    //For this type of View, the template is the name of the method..
    String templateClassName = view.getRelativeOrAbsolutePath();
    int lastIndexOf = templateClassName.lastIndexOf(".");
    String extension = null;
    if (lastIndexOf > 0) {
        extension = templateClassName.substring(lastIndexOf + 1);
    }
    String templatePath = templateClassName;
    if (!templatePath.startsWith("/")) {
        //relative path so need to form absolute path...
        if (lastIndexOf > 0) {
            templateClassName = templateClassName.substring(0, lastIndexOf);
        }
        templatePath = getTemplatePath(packageStr, templateClassName, extension);
    }
    //TODO: stream this out with chunked response instead??....
    StringWriter out = new StringWriter();
    try {
        templatingService.loadAndRunTemplate(templatePath, out, resp.pageArgs);
    } catch (MissingPropertyException e) {
        Set<String> keys = resp.pageArgs.keySet();
        throw new ControllerPageArgsException("Controller.method=" + view.getControllerName() + "." + view.getMethodName() + " did\nnot" + " return enough arguments for the template =" + templatePath + ".  specifically, the method\nreturned these" + " arguments=" + keys + "  There is a chance in your html you forgot the '' around a variable name\n" + "such as #{set 'key'}# but you put #{set key}# which is 'usually' not the correct way\n" + "The missing properties are as follows....\n" + e.getMessage(), e);
    }
    String content = out.toString();
    StatusCode statusCode = StatusCode.HTTP_200_OK;
    switch(resp.routeType) {
        case HTML:
            statusCode = StatusCode.HTTP_200_OK;
            break;
        case NOT_FOUND:
            statusCode = StatusCode.HTTP_404_NOTFOUND;
            break;
        case INTERNAL_SERVER_ERROR:
            statusCode = StatusCode.HTTP_500_INTERNAL_SVR_ERROR;
            break;
        default:
            throw new IllegalStateException("did add case for state=" + resp.routeType);
    }
    //NOTE: These are ALL String templates, so default the mimeType to text/plain
    if (extension == null) {
        extension = "txt";
    }
    return createResponseAndSend(statusCode, content, extension, "text/plain");
}
Also used : Set(java.util.Set) StringWriter(java.io.StringWriter) MissingPropertyException(groovy.lang.MissingPropertyException) View(org.webpieces.router.api.dto.View) StatusCode(com.webpieces.http2parser.api.dto.StatusCode)

Aggregations

MissingPropertyException (groovy.lang.MissingPropertyException)16 GString (groovy.lang.GString)4 MetaClass (groovy.lang.MetaClass)4 MissingMethodException (groovy.lang.MissingMethodException)4 Script (groovy.lang.Script)4 Tuple (groovy.lang.Tuple)4 IOException (java.io.IOException)4 Binding (groovy.lang.Binding)3 DelegatingMetaClass (groovy.lang.DelegatingMetaClass)3 PrintWriter (java.io.PrintWriter)3 Method (java.lang.reflect.Method)3 CompiledScript (javax.script.CompiledScript)3 ScriptException (javax.script.ScriptException)3 CompilationFailedException (org.codehaus.groovy.control.CompilationFailedException)3 MethodClosure (org.codehaus.groovy.runtime.MethodClosure)3 MetaProperty (groovy.lang.MetaProperty)2 Range (groovy.lang.Range)2 Writer (java.io.Writer)2 SQLException (java.sql.SQLException)2 Iterator (java.util.Iterator)2