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