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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations