Search in sources :

Example 1 with AttributeFieldError

use of com.agiletec.aps.system.common.entity.model.AttributeFieldError 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 AttributeFieldError

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

the class AbstractResourceAttribute method validate.

@Override
public List<AttributeFieldError> validate(AttributeTracer tracer) {
    List<AttributeFieldError> errors = super.validate(tracer);
    try {
        if (null == this.getResources()) {
            return errors;
        }
        List<Lang> langs = super.getLangManager().getLangs();
        for (int i = 0; i < langs.size(); i++) {
            Lang lang = langs.get(i);
            ResourceInterface resource = this.getResource(lang.getCode());
            if (null == resource) {
                continue;
            }
            AttributeTracer resourceTracer = (AttributeTracer) tracer.clone();
            resourceTracer.setLang(lang);
            String resourceMainGroup = resource.getMainGroup();
            Content parentContent = (Content) this.getParentEntity();
            if (!resourceMainGroup.equals(Group.FREE_GROUP_NAME) && !resourceMainGroup.equals(parentContent.getMainGroup()) && !parentContent.getGroups().contains(resourceMainGroup)) {
                AttributeFieldError fieldError = new AttributeFieldError(this, ICmsAttributeErrorCodes.INVALID_RESOURCE_GROUPS, resourceTracer);
                fieldError.setMessage("Invalid resource group - " + resourceMainGroup);
                errors.add(fieldError);
            }
        }
    } catch (Throwable t) {
        logger.error("Error validating text attribute", t);
        throw new RuntimeException("Error validating text attribute", t);
    }
    return errors;
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) Content(com.agiletec.plugins.jacms.aps.system.services.content.model.Content) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) Lang(com.agiletec.aps.system.services.lang.Lang) ResourceInterface(com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)

Example 3 with AttributeFieldError

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

the class CmsHypertextAttribute method validate.

@Override
public List<AttributeFieldError> validate(AttributeTracer tracer) {
    List<AttributeFieldError> errors = super.validate(tracer);
    try {
        List<Lang> langs = this.getLangManager().getLangs();
        for (Lang lang : langs) {
            AttributeTracer textTracer = (AttributeTracer) tracer.clone();
            textTracer.setLang(lang);
            String text = this.getTextMap().get(lang.getCode());
            if (null == text) {
                continue;
            }
            List<SymbolicLink> links = HypertextAttributeUtil.getSymbolicLinksOnText(text);
            if (null != links && !links.isEmpty()) {
                SymbolicLinkValidator sler = new SymbolicLinkValidator(this.getContentManager(), this.getPageManager());
                for (SymbolicLink symbLink : links) {
                    String linkErrorCode = sler.scan(symbLink, (Content) this.getParentEntity());
                    if (null != linkErrorCode) {
                        AttributeFieldError error = new AttributeFieldError(this, linkErrorCode, textTracer);
                        error.setMessage("Invalid link - page " + symbLink.getPageDest() + " - content " + symbLink.getContentDest() + " - Error code " + linkErrorCode);
                        errors.add(error);
                    }
                }
            }
        }
    } catch (Throwable t) {
        logger.error("Error validating Attribute '{}'", this.getName(), t);
        throw new RuntimeException("Error validating Attribute '" + this.getName() + "'", t);
    }
    return errors;
}
Also used : SymbolicLinkValidator(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.util.SymbolicLinkValidator) AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) Lang(com.agiletec.aps.system.services.lang.Lang) SymbolicLink(com.agiletec.plugins.jacms.aps.system.services.content.model.SymbolicLink)

Example 4 with AttributeFieldError

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

the class LinkAttribute method validate.

@Override
public List<AttributeFieldError> validate(AttributeTracer tracer) {
    List<AttributeFieldError> errors = super.validate(tracer);
    try {
        SymbolicLink symbolicLink = this.getSymbolicLink();
        if (null == symbolicLink) {
            return errors;
        }
        SymbolicLinkValidator sler = new SymbolicLinkValidator(this.getContentManager(), this.getPageManager());
        String linkErrorCode = sler.scan(symbolicLink, (Content) this.getParentEntity());
        if (null != linkErrorCode) {
            AttributeFieldError error = new AttributeFieldError(this, linkErrorCode, tracer);
            error.setMessage("Invalid link - page " + symbolicLink.getPageDest() + " - content " + symbolicLink.getContentDest() + " - Error code " + linkErrorCode);
            errors.add(error);
        }
    } catch (Throwable t) {
        logger.error("Error validating link attribute", t);
        throw new RuntimeException("Error validating link attribute", t);
    }
    return errors;
}
Also used : SymbolicLinkValidator(com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.util.SymbolicLinkValidator) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) SymbolicLink(com.agiletec.plugins.jacms.aps.system.services.content.model.SymbolicLink)

Example 5 with AttributeFieldError

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

the class ListAttribute method validate.

@Override
public List<AttributeFieldError> validate(AttributeTracer tracer) {
    List<AttributeFieldError> errors = super.validate(tracer);
    try {
        List<Lang> langs = super.getLangManager().getLangs();
        for (int i = 0; i < langs.size(); i++) {
            Lang lang = langs.get(i);
            List<AttributeInterface> attributeList = this.getAttributeList(lang.getCode());
            for (int j = 0; j < attributeList.size(); j++) {
                AttributeInterface attributeElement = attributeList.get(j);
                AttributeTracer elementTracer = (AttributeTracer) tracer.clone();
                elementTracer.setListElement(true);
                elementTracer.setListLang(lang);
                elementTracer.setListIndex(j);
                Status elementStatus = attributeElement.getStatus();
                if (elementStatus.equals(Status.EMPTY)) {
                    errors.add(new AttributeFieldError(attributeElement, FieldError.INVALID, elementTracer));
                } else {
                    List<AttributeFieldError> elementErrors = attributeElement.validate(elementTracer);
                    if (null != elementErrors) {
                        errors.addAll(elementErrors);
                    }
                }
            }
        }
    } catch (Throwable t) {
        // ApsSystemUtils.logThrowable(t, this, "validate");
        _logger.error("Error validating list attribute", t);
        throw new RuntimeException("Error validating list attribute", t);
    }
    return errors;
}
Also used : AttributeTracer(com.agiletec.aps.system.common.entity.model.AttributeTracer) AttributeFieldError(com.agiletec.aps.system.common.entity.model.AttributeFieldError) Lang(com.agiletec.aps.system.services.lang.Lang)

Aggregations

AttributeFieldError (com.agiletec.aps.system.common.entity.model.AttributeFieldError)18 AttributeTracer (com.agiletec.aps.system.common.entity.model.AttributeTracer)8 ArrayList (java.util.ArrayList)5 Lang (com.agiletec.aps.system.services.lang.Lang)4 FieldError (com.agiletec.aps.system.common.entity.model.FieldError)3 ApsSystemException (com.agiletec.aps.system.exception.ApsSystemException)3 ApiError (org.entando.entando.aps.system.services.api.model.ApiError)3 SymbolicLink (com.agiletec.plugins.jacms.aps.system.services.content.model.SymbolicLink)2 SymbolicLinkValidator (com.agiletec.plugins.jacms.aps.system.services.content.model.extraAttribute.util.SymbolicLinkValidator)2 AttributeInterface (com.agiletec.aps.system.common.entity.model.attribute.AttributeInterface)1 DateAttribute (com.agiletec.aps.system.common.entity.model.attribute.DateAttribute)1 ITextAttribute (com.agiletec.aps.system.common.entity.model.attribute.ITextAttribute)1 NumberAttribute (com.agiletec.aps.system.common.entity.model.attribute.NumberAttribute)1 IAttributeValidationRules (com.agiletec.aps.system.common.entity.model.attribute.util.IAttributeValidationRules)1 IndexableAttributeInterface (com.agiletec.aps.system.common.searchengine.IndexableAttributeInterface)1 AttributeManagerInterface (com.agiletec.apsadmin.system.entity.attribute.manager.AttributeManagerInterface)1 Content (com.agiletec.plugins.jacms.aps.system.services.content.model.Content)1 ResourceInterface (com.agiletec.plugins.jacms.aps.system.services.resource.model.ResourceInterface)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1