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