use of com.qcadoo.model.api.FieldDefinition in project qcadoo by qcadoo.
the class GridComponentPattern method parseColumnOption.
private void parseColumnOption(final ComponentOption option) {
GridComponentColumn column = new GridComponentColumn(option.getAttributeValue("name"));
String fields = option.getAttributeValue("fields");
if (Objects.nonNull(fields)) {
for (FieldDefinition field : parseFields(fields, column)) {
column.addField(field);
}
}
column.setAuthorizationRole(parseColumnAuthorizationRole(option));
column.setAlign(parseColumnAlignOption(option));
column.setExpression(option.getAttributeValue("expression"));
String columnWidth = option.getAttributeValue("width");
if (Objects.nonNull(columnWidth)) {
column.setWidth(Integer.valueOf(columnWidth));
}
if (Objects.nonNull(option.getAttributeValue("link"))) {
column.setLink(Boolean.parseBoolean(option.getAttributeValue("link")));
}
if (Objects.nonNull(option.getAttributeValue("hidden"))) {
column.setHidden(Boolean.parseBoolean(option.getAttributeValue("hidden")));
}
column.setClassesNames(option.getAttributeValue("classesNames"));
column.setClassesCondition(option.getAttributeValue("classesCondition"));
column.setFormatter(option.getAttributeValue("formatter"));
column.setCorrespondingView(option.getAttributeValue("correspondingView"));
column.setCorrespondingField(option.getAttributeValue("correspondingField"));
column.setCorrespondingViewField(option.getAttributeValue("correspondingViewField"));
if (Objects.nonNull(option.getAttributeValue("attachment"))) {
column.setAttachment(Boolean.parseBoolean(option.getAttributeValue("attachment")));
}
columns.put(column.getName(), column);
}
use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.
the class StateChangeViewClientValidationUtilTest method mockFieldDefinition.
private FieldDefinition mockFieldDefinition(final String name) {
final FieldDefinition fieldDefinition = mock(FieldDefinition.class);
given(fieldDefinition.getName()).willReturn(name);
return fieldDefinition;
}
use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.
the class StateChangeViewClientValidationUtilTest method shouldAddValidationErrorToFormIfFieldIsNull.
@Test
public final void shouldAddValidationErrorToFormIfFieldIsNull() {
// given
DataDefinition dataDefinition = mockDataDefinition(Lists.<FieldDefinition>newArrayList());
given(entity.getDataDefinition()).willReturn(dataDefinition);
given(formComponent.getEntity()).willReturn(entity);
Entity message = mockValidationErrorMsg(null, false, TRANSLATION_KEY);
given(messagesHolder.getAllMessages()).willReturn(Lists.newArrayList(message));
// when
validationUtil.addValidationErrorMessages(formComponent, entity, messagesHolder);
// then
verify(entity, Mockito.never()).addError(Mockito.any(FieldDefinition.class), Mockito.eq(TRANSLATION_KEY));
verify(formComponent).addTranslatedMessage(Mockito.any(String.class), Mockito.eq(convertViewMessageType(VALIDATION_ERROR)), Mockito.any(Boolean.class));
}
use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.
the class StateChangeViewClientValidationUtilTest method shouldAddValidationErrorToFormIfFieldDoesNotExist.
@Test
public final void shouldAddValidationErrorToFormIfFieldDoesNotExist() {
// given
DataDefinition dataDefinition = mockDataDefinition(Lists.<FieldDefinition>newArrayList());
given(entity.getDataDefinition()).willReturn(dataDefinition);
given(formComponent.getEntity()).willReturn(entity);
Entity message = mockValidationErrorMsg("notExistingField", false, TRANSLATION_KEY);
given(messagesHolder.getAllMessages()).willReturn(Lists.newArrayList(message));
// when
validationUtil.addValidationErrorMessages(formComponent, entity, messagesHolder);
// then
verify(entity, Mockito.never()).addError(Mockito.any(FieldDefinition.class), Mockito.eq(TRANSLATION_KEY));
verify(formComponent).addTranslatedMessage(Mockito.any(String.class), Mockito.eq(convertViewMessageType(VALIDATION_ERROR)), Mockito.any(Boolean.class));
}
use of com.qcadoo.model.api.FieldDefinition in project mes by qcadoo.
the class StateChangeViewClientValidationUtilTest method shouldAddValidationErrorToEntityField.
@Test
public final void shouldAddValidationErrorToEntityField() {
// given
final String existingFieldName = "existingField";
FieldDefinition existingField = mockFieldDefinition(existingFieldName);
DataDefinition dataDefinition = mockDataDefinition(Lists.newArrayList(existingField));
given(entity.getDataDefinition()).willReturn(dataDefinition);
given(formComponent.getEntity()).willReturn(entity);
Entity message = mockValidationErrorMsg(existingFieldName, false, TRANSLATION_KEY);
given(messagesHolder.getAllMessages()).willReturn(Lists.newArrayList(message));
// when
validationUtil.addValidationErrorMessages(formComponent, entity, messagesHolder);
// then
verify(entity).addError(existingField, TRANSLATION_KEY);
}
Aggregations