Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QFJ-981 / QFJ-982 Remove settings from DataDictionary class #831

Merged
merged 24 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e4f32ce
QFJ-982 Rework Data Dictionary handling to separate DataDictionarySet…
Nov 26, 2019
c6d49c8
Update to the executor example code
Nov 26, 2019
17cdb4a
Set proper default in SFTS
Nov 28, 2019
cf6ddfd
Added test for QFJ-981
chrjohn Nov 29, 2019
10d3678
Adding some missing DataDictionary tests and fixing test name
Dec 2, 2019
0ab4b4d
Fix new test
Dec 2, 2019
3e43b2d
Rename DataDictionarySettings to ValidationSettings
Dec 2, 2019
568aa6c
Some further renaming to match usage of ValidationSettings
Dec 5, 2019
ffbbdac
Merge branch 'master' into github-dds
chrjohn Jan 7, 2020
b2cc08f
updated DataDictionaryTest
chrjohn Jan 7, 2020
a0487cf
Update DataDictionaryTest.java
chrjohn Jan 8, 2020
b2edcf0
Merge branch 'master' into github-dds
chrjohn Jan 20, 2020
062094e
Merge branch 'github-dds' of https://github.com/philipwhiuk/quickfixj…
chrjohn Jun 20, 2024
054d49f
Update MessageTest.java
chrjohn Jun 20, 2024
165e452
adapted constructor
chrjohn Jun 21, 2024
493f9c7
removed tests that were removed with https://github.com/quickfix-j/qu…
chrjohn Jun 21, 2024
aaa2d06
corrected merge issues
chrjohn Jun 21, 2024
f520577
typo
chrjohn Jun 21, 2024
f9490ba
corrected method calls
chrjohn Jun 21, 2024
d610896
check if validationSettings is not NULL
chrjohn Jun 21, 2024
71781a9
corrected variable name
chrjohn Jun 21, 2024
786148e
Merge branch 'master' into philipwhiuk-github-dds
chrjohn Jun 21, 2024
7c60b1c
Merge branch 'master' into philipwhiuk-github-dds
chrjohn Jun 21, 2024
de99ac6
NULL safety
chrjohn Jun 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 28 additions & 115 deletions quickfixj-base/src/main/java/quickfix/DataDictionary.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ private static Supplier<DocumentBuilderFactory> createDocumentBuilderFactorySupp
}

private boolean hasVersion = false;
private boolean checkFieldsOutOfOrder = true;
private boolean checkFieldsHaveValues = true;
private boolean checkUserDefinedFields = true;
private boolean checkUnorderedGroupFields = true;
private boolean allowUnknownMessageFields = false;
private String beginString;
private String fullVersion;
private String majorVersion;
Expand Down Expand Up @@ -532,86 +527,6 @@ private boolean isMultipleValueStringField(int field) {
fieldType == FieldType.MULTIPLECHARVALUE;
}

/**
* Controls whether out of order fields are checked.
*
* @param flag true = checked, false = not checked
*/
public void setCheckFieldsOutOfOrder(boolean flag) {
checkFieldsOutOfOrder = flag;
}

public boolean isCheckFieldsOutOfOrder() {
return checkFieldsOutOfOrder;
}

public boolean isCheckUnorderedGroupFields() {
return checkUnorderedGroupFields;
}

public boolean isCheckFieldsHaveValues() {
return checkFieldsHaveValues;
}

public boolean isCheckUserDefinedFields() {
return checkUserDefinedFields;
}

public boolean isAllowUnknownMessageFields() {
return allowUnknownMessageFields;
}

/**
* Controls whether group fields are in the same order
*
* @param flag true = checked, false = not checked
*/
public void setCheckUnorderedGroupFields(boolean flag) {
checkUnorderedGroupFields = flag;
for (Map<Integer, GroupInfo> gm : groups.values()) {
for (GroupInfo gi : gm.values()) {
gi.getDataDictionary().setCheckUnorderedGroupFields(flag);
}
}
}

/**
* Controls whether empty field values are checked.
*
* @param flag true = checked, false = not checked
*/
public void setCheckFieldsHaveValues(boolean flag) {
checkFieldsHaveValues = flag;
for (Map<Integer, GroupInfo> gm : groups.values()) {
for (GroupInfo gi : gm.values()) {
gi.getDataDictionary().setCheckFieldsHaveValues(flag);
}
}
}

/**
* Controls whether user defined fields are checked.
*
* @param flag true = checked, false = not checked
*/
public void setCheckUserDefinedFields(boolean flag) {
checkUserDefinedFields = flag;
for (Map<Integer, GroupInfo> gm : groups.values()) {
for (GroupInfo gi : gm.values()) {
gi.getDataDictionary().setCheckUserDefinedFields(flag);
}
}
}

public void setAllowUnknownMessageFields(boolean allowUnknownFields) {
allowUnknownMessageFields = allowUnknownFields;
for (Map<Integer, GroupInfo> gm : groups.values()) {
for (GroupInfo gi : gm.values()) {
gi.getDataDictionary().setAllowUnknownMessageFields(allowUnknownFields);
}
}
}

private void copyFrom(DataDictionary rhs) {
hasVersion = rhs.hasVersion;
beginString = rhs.beginString;
Expand All @@ -632,13 +547,6 @@ private void copyFrom(DataDictionary rhs) {
copyMap(valueNames, rhs.valueNames);
copyGroups(groups, rhs.groups);
copyMap(components, rhs.components);

setCheckFieldsOutOfOrder(rhs.checkFieldsOutOfOrder);
setCheckFieldsHaveValues(rhs.checkFieldsHaveValues);
setCheckUserDefinedFields(rhs.checkUserDefinedFields);
setCheckUnorderedGroupFields(rhs.checkUnorderedGroupFields);
setAllowUnknownMessageFields(rhs.allowUnknownMessageFields);

calculateOrderedFields();
}

Expand Down Expand Up @@ -688,34 +596,39 @@ private static <V> void copyCollection(Collection<V> lhs, Collection<V> rhs) {
* Validate a message, including the header and trailer fields.
*
* @param message the message
* @param settings
* @throws IncorrectTagValue if a field value is not valid
* @throws FieldNotFound if a field cannot be found
* @throws IncorrectDataFormat if a field value has a wrong data type
*/
public void validate(Message message) throws IncorrectTagValue, FieldNotFound,
public void validate(Message message, ValidationSettings settings) throws IncorrectTagValue, FieldNotFound,
IncorrectDataFormat {
validate(message, false);
validate(message, false, settings);
}

/**
* Validate the message body, with header and trailer fields being validated conditionally.
*
* @param message the message
* @param bodyOnly whether to validate just the message body, or to validate the header and trailer sections as well.
* @param settings
* @throws IncorrectTagValue if a field value is not valid
* @throws FieldNotFound if a field cannot be found
* @throws IncorrectDataFormat if a field value has a wrong data type
*/
public void validate(Message message, boolean bodyOnly) throws IncorrectTagValue,
public void validate(Message message, boolean bodyOnly, ValidationSettings settings) throws IncorrectTagValue,
FieldNotFound, IncorrectDataFormat {
validate(message, bodyOnly ? null : this, this);
validate(message, bodyOnly ? null : this, this, settings);
}

static void validate(Message message, DataDictionary sessionDataDictionary,
DataDictionary applicationDataDictionary) throws IncorrectTagValue, FieldNotFound,
DataDictionary applicationDataDictionary, ValidationSettings settings) throws IncorrectTagValue, FieldNotFound,
IncorrectDataFormat {
final boolean bodyOnly = sessionDataDictionary == null;

if (settings == null) {
settings = new ValidationSettings();
}

if (isVersionSpecified(sessionDataDictionary)
&& !sessionDataDictionary.getVersion().equals(
message.getHeader().getString(BeginString.FIELD))
Expand All @@ -737,38 +650,38 @@ static void validate(Message message, DataDictionary sessionDataDictionary,
}

if (!bodyOnly) {
sessionDataDictionary.iterate(message.getHeader(), HEADER_ID, sessionDataDictionary);
sessionDataDictionary.iterate(message.getTrailer(), TRAILER_ID, sessionDataDictionary);
sessionDataDictionary.iterate(settings, message.getHeader(), HEADER_ID, sessionDataDictionary);
sessionDataDictionary.iterate(settings, message.getTrailer(), TRAILER_ID, sessionDataDictionary);
}

applicationDataDictionary.iterate(message, msgType, applicationDataDictionary);
applicationDataDictionary.iterate(settings, message, msgType, applicationDataDictionary);
}

private static boolean isVersionSpecified(DataDictionary dd) {
return dd != null && dd.hasVersion;
}

private void iterate(FieldMap map, String msgType, DataDictionary dd) throws IncorrectTagValue,
private void iterate(ValidationSettings settings, FieldMap map, String msgType, DataDictionary dd) throws IncorrectTagValue,
IncorrectDataFormat {
for (final Field<?> f : map) {
final StringField field = (StringField) f;

checkHasValue(field);
checkHasValue(settings, field);

if (hasVersion) {
checkValidFormat(field);
checkValidFormat(settings, field);
checkValue(field);
}

if (beginString != null) {
dd.checkField(field, msgType, map instanceof Message);
dd.checkField(settings, field, msgType, map instanceof Message);
dd.checkGroupCount(field, map, msgType);
}
}

for (final List<Group> groups : map.getGroups().values()) {
for (final Group group : groups) {
iterate(group, msgType, dd.getGroup(msgType, group.getFieldTag())
iterate(settings, group, msgType, dd.getGroup(msgType, group.getFieldTag())
.getDataDictionary());
}
}
Expand All @@ -789,10 +702,10 @@ void checkValidTagNumber(Field<?> field) {
}

/** Check if field tag is defined for message or group **/
void checkField(Field<?> field, String msgType, boolean message) {
void checkField(ValidationSettings settings, Field<?> field, String msgType, boolean message) {
// use different validation for groups and messages
boolean messageField = message ? isMsgField(msgType, field.getField()) : fields.contains(field.getField());
boolean fail = checkFieldFailure(field.getField(), messageField);
boolean fail = checkFieldFailure(settings, field.getField(), messageField);

if (fail) {
if (fields.contains(field.getField())) {
Expand All @@ -803,22 +716,22 @@ void checkField(Field<?> field, String msgType, boolean message) {
}
}

boolean checkFieldFailure(int field, boolean messageField) {
boolean checkFieldFailure(ValidationSettings settings, int field, boolean messageField) {
boolean fail;
if (field < USER_DEFINED_TAG_MIN) {
fail = !messageField && !allowUnknownMessageFields;
fail = !messageField && !settings.allowUnknownMessageFields;
} else {
fail = !messageField && checkUserDefinedFields;
fail = !messageField && settings.checkUserDefinedFields;
}
return fail;
}

private void checkValidFormat(StringField field) throws IncorrectDataFormat {
private void checkValidFormat(ValidationSettings settings, StringField field) throws IncorrectDataFormat {
FieldType fieldType = getFieldType(field.getTag());
if (fieldType == null) {
return;
}
if (!checkFieldsHaveValues && field.getValue().length() == 0) {
if (!settings.checkFieldsHaveValues && field.getValue().length() == 0) {
return;
}
try {
Expand Down Expand Up @@ -883,8 +796,8 @@ private void checkValue(StringField field) throws IncorrectTagValue {
}

/** Check if a field has a value. **/
private void checkHasValue(StringField field) {
if (checkFieldsHaveValues && field.getValue().length() == 0) {
private void checkHasValue(ValidationSettings settings, StringField field) {
if (settings.checkFieldsHaveValues && field.getValue().length() == 0) {
throw new FieldException(SessionRejectReason.TAG_SPECIFIED_WITHOUT_A_VALUE,
field.getField());
}
Expand Down
Loading