Search in sources :

Example 1 with FieldError

use of com.agiletec.aps.system.common.entity.model.FieldError in project entando-core by entando.

the class ApiDataObjectInterface method validate.

private List<ApiError> validate(DataObject dataObject) throws ApsSystemException {
    List<ApiError> errors = new ArrayList<ApiError>();
    try {
        if (null == dataObject.getMainGroup()) {
            errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Main group null", Response.Status.CONFLICT));
        }
        List<FieldError> fieldErrors = dataObject.validate(this.getGroupManager());
        if (null != fieldErrors) {
            for (int i = 0; i < fieldErrors.size(); i++) {
                FieldError fieldError = fieldErrors.get(i);
                if (fieldError instanceof AttributeFieldError) {
                    AttributeFieldError attributeError = (AttributeFieldError) fieldError;
                    errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, attributeError.getFullMessage(), Response.Status.CONFLICT));
                } else {
                    errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, fieldError.getMessage(), Response.Status.CONFLICT));
                }
            }
        }
    } catch (Throwable t) {
        _logger.error("Error validating DataObject", t);
        throw new ApsSystemException("Error validating DataObject", t);
    }
    return errors;
}
Also used : ArrayList(java.util.ArrayList) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) FieldError(com.agiletec.aps.system.common.entity.model.FieldError) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) ApsSystemException(com.agiletec.aps.system.exception.ApsSystemException) ApiError(org.entando.entando.aps.system.services.api.model.ApiError)

Example 2 with FieldError

use of com.agiletec.aps.system.common.entity.model.FieldError in project entando-core by entando.

the class TestValidateContent method testValidate_4.

public void testValidate_4() throws Throwable {
    String shortTitle = "short";
    String longTitle = "Titolo che supera la lunghezza massima di cento caratteri; " + "Ripeto, Titolo che supera la lunghezza massima di cento caratteri";
    try {
        Content content = this.createNewVoid("RAH", "descr", Content.STATUS_DRAFT, Group.FREE_GROUP_NAME, "admin");
        ITextAttribute textAttribute = (ITextAttribute) content.getAttribute("Titolo");
        textAttribute.setText(shortTitle, "it");
        List<FieldError> errors = content.validate(this._groupManager);
        assertEquals(1, errors.size());
        FieldError error = errors.get(0);
        assertEquals("Text:it_Titolo", error.getFieldCode());
        assertEquals(FieldError.INVALID_MIN_LENGTH, error.getErrorCode());
        textAttribute.setText(longTitle, "it");
        errors = content.validate(this._groupManager);
        assertEquals(1, errors.size());
        error = errors.get(0);
        assertEquals("Text:it_Titolo", error.getFieldCode());
        assertEquals(FieldError.INVALID_MAX_LENGTH, error.getErrorCode());
        textAttribute.setText(shortTitle, "en");
        errors = content.validate(this._groupManager);
        assertEquals(2, errors.size());
        error = errors.get(0);
        assertEquals("Text:it_Titolo", error.getFieldCode());
        assertEquals(FieldError.INVALID_MAX_LENGTH, error.getErrorCode());
        error = errors.get(1);
        assertEquals("Text:en_Titolo", error.getFieldCode());
        assertEquals(FieldError.INVALID_MIN_LENGTH, error.getErrorCode());
    } catch (Throwable t) {
        throw t;
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) FieldError(com.agiletec.aps.system.common.entity.model.FieldError)

Example 3 with FieldError

use of com.agiletec.aps.system.common.entity.model.FieldError in project entando-core by entando.

the class TestValidateContent method testValidate_1.

public void testValidate_1() throws Throwable {
    String insertedDescr = "XXX Prova Validazione XXX";
    try {
        Content content = this.createNewVoid("ART", insertedDescr, Content.STATUS_DRAFT, Group.FREE_GROUP_NAME, "admin");
        List<FieldError> errors = content.validate(this._groupManager);
        assertNotNull(errors);
        assertEquals(1, errors.size());
        FieldError error = errors.get(0);
        // Verifica obbligatorietĂ  attributo "Titolo"
        assertEquals("Text:it_Titolo", error.getFieldCode());
        assertEquals(FieldError.MANDATORY, error.getErrorCode());
        String monolistAttributeName = "Autori";
        MonoListAttribute monolist = (MonoListAttribute) content.getAttribute(monolistAttributeName);
        monolist.addAttribute();
        assertEquals(1, monolist.getAttributes().size());
        errors = content.validate(this._groupManager);
        assertEquals(2, errors.size());
        error = errors.get(0);
        // Verifica obbligatorietĂ  attributo "Titolo"
        assertEquals("Text:it_Titolo", error.getFieldCode());
        assertEquals(FieldError.MANDATORY, error.getErrorCode());
        error = errors.get(1);
        // Verifica non valido elemento 1 in attributo lista "Autori"
        assertEquals("Monolist:Monotext:Autori_0", error.getFieldCode());
        assertEquals(FieldError.INVALID, error.getErrorCode());
    } catch (Throwable t) {
        throw t;
    }
}
Also used : MonoListAttribute(com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) FieldError(com.agiletec.aps.system.common.entity.model.FieldError)

Example 4 with FieldError

use of com.agiletec.aps.system.common.entity.model.FieldError in project entando-core by entando.

the class TestValidateDataObject method testValidate_2.

public void testValidate_2() throws Throwable {
    try {
        DataObject content = this.createNewVoid("RAH", "descr", DataObject.STATUS_DRAFT, Group.FREE_GROUP_NAME, "admin");
        ITextAttribute emailAttribute = (ITextAttribute) content.getAttribute("email");
        emailAttribute.setText("wrongEmailAddress", null);
        List<FieldError> errors = content.validate(this._groupManager);
        assertEquals(1, errors.size());
        FieldError error = errors.get(0);
        assertEquals("Monotext:email", error.getFieldCode());
        assertEquals(FieldError.INVALID_FORMAT, error.getErrorCode());
    } catch (Throwable t) {
        throw t;
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) FieldError(com.agiletec.aps.system.common.entity.model.FieldError)

Example 5 with FieldError

use of com.agiletec.aps.system.common.entity.model.FieldError in project entando-core by entando.

the class TestValidateDataObject method testValidate_4.

public void testValidate_4() throws Throwable {
    String shortTitle = "short";
    String longTitle = "Titolo che supera la lunghezza massima di cento caratteri; " + "Ripeto, Titolo che supera la lunghezza massima di cento caratteri";
    try {
        DataObject content = this.createNewVoid("RAH", "descr", DataObject.STATUS_DRAFT, Group.FREE_GROUP_NAME, "admin");
        ITextAttribute textAttribute = (ITextAttribute) content.getAttribute("Titolo");
        textAttribute.setText(shortTitle, "it");
        List<FieldError> errors = content.validate(this._groupManager);
        assertEquals(1, errors.size());
        FieldError error = errors.get(0);
        assertEquals("Text:it_Titolo", error.getFieldCode());
        assertEquals(FieldError.INVALID_MIN_LENGTH, error.getErrorCode());
        textAttribute.setText(longTitle, "it");
        errors = content.validate(this._groupManager);
        assertEquals(1, errors.size());
        error = errors.get(0);
        assertEquals("Text:it_Titolo", error.getFieldCode());
        assertEquals(FieldError.INVALID_MAX_LENGTH, error.getErrorCode());
        textAttribute.setText(shortTitle, "en");
        errors = content.validate(this._groupManager);
        assertEquals(2, errors.size());
        error = errors.get(0);
        assertEquals("Text:it_Titolo", error.getFieldCode());
        assertEquals(FieldError.INVALID_MAX_LENGTH, error.getErrorCode());
        error = errors.get(1);
        assertEquals("Text:en_Titolo", error.getFieldCode());
        assertEquals(FieldError.INVALID_MIN_LENGTH, error.getErrorCode());
    } catch (Throwable t) {
        throw t;
    }
}
Also used : ITextAttribute(com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) FieldError(com.agiletec.aps.system.common.entity.model.FieldError)

Aggregations

FieldError (com.agiletec.aps.system.common.entity.model.FieldError)10 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)4 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)4 AttributeFieldError (com.agiletec.aps.system.common.entity.model.AttributeFieldError)3 MonoListAttribute (com.agiletec.aps.system.common.entity.model.attribute.MonoListAttribute)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)3 ArrayList (java.util.ArrayList)3 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)3 DataObject (org.entando.entando.aps.system.services.dataobject.model.DataObject)3 SymbolicLink (com.agiletec.plugins.jacms.aps.system.services.content.model.SymbolicLink)1 LinkAttribute (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.LinkAttribute)1