Search in sources :

Example 6 with FieldError

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

the class ApiContentInterface method validate.

private List<ApiError> validate(Content content) throws ApsSystemException {
    List<ApiError> errors = new ArrayList<ApiError>();
    try {
        if (null == content.getMainGroup()) {
            errors.add(new ApiError(IApiErrorCodes.API_VALIDATION_ERROR, "Main group null", Response.Status.CONFLICT));
        }
        List<FieldError> fieldErrors = content.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 content", t);
        throw new ApsSystemException("Error validating content", 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 7 with FieldError

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

the class TestValidateDataObject method testValidate_1.

public void testValidate_1() throws Throwable {
    String insertedDescr = "XXX Prova Validazione XXX";
    try {
        DataObject content = this.createNewVoid("ART", insertedDescr, DataObject.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) DataObject(org.entando.entando.aps.system.services.dataobject.model.DataObject) FieldError(com.agiletec.aps.system.common.entity.model.FieldError)

Example 8 with FieldError

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

the class ApiUserProfileInterface method validate.

private List<ApiError> validate(IUserProfile userProfile) throws ApsSystemException {
    List<ApiError> errors = new ArrayList<ApiError>();
    try {
        List<FieldError> fieldErrors = userProfile.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 profile", t);
        // ApsSystemUtils.logThrowable(t, this, "validate");
        throw new ApsSystemException("Error validating profile", 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 9 with FieldError

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

the class TestValidateContent method testValidate_2.

public void testValidate_2() throws Throwable {
    try {
        Content content = this._contentManager.loadContent("EVN191", true);
        content.setId(null);
        // Valorizzo il gruppo proprietario
        content.setMainGroup(Group.FREE_GROUP_NAME);
        content.getGroups().add("customers");
        MonoListAttribute linksCorrelati = (MonoListAttribute) content.getAttribute("LinkCorrelati");
        LinkAttribute linkAttribute = (LinkAttribute) linksCorrelati.addAttribute();
        List<FieldError> errors = content.validate(this._groupManager);
        assertNotNull(errors);
        assertEquals(1, errors.size());
        FieldError error = errors.get(0);
        // Verifica obbligatorietĂ  attributo "Titolo"
        assertEquals("Monolist:Link:LinkCorrelati_0", error.getFieldCode());
        assertEquals(FieldError.INVALID, error.getErrorCode());
        // AGGIUNGO LINK SU PAGINA COACH
        linkAttribute.setText("Descrizione link", "it");
        SymbolicLink symbolicLink = new SymbolicLink();
        // Contenuto di coach
        symbolicLink.setDestinationToContent("EVN103");
        linkAttribute.setSymbolicLink(symbolicLink);
        errors = content.validate(this._groupManager);
        assertNotNull(errors);
        assertEquals(1, errors.size());
        error = errors.get(0);
        assertEquals("Monolist:Link:LinkCorrelati_0", error.getFieldCode());
        assertEquals(ICmsAttributeErrorCodes.INVALID_CONTENT_GROUPS, error.getErrorCode());
    } catch (Throwable t) {
        throw t;
    }
}
Also used : LinkAttribute(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.LinkAttribute) 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) SymbolicLink(com.agiletec.plugins.jacms.aps.system.services.content.model.SymbolicLink)

Example 10 with FieldError

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

the class TestValidateContent method testValidate_3.

public void testValidate_3() throws Throwable {
    try {
        Content content = this.createNewVoid("RAH", "descr", Content.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) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) 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