Skip to content

Commit 43b4cf4

Browse files
committed
Fixes BroadleafCommerce#1510 - by adding the ability for a FieldData object to explicitly indicate that it should not be validated.
Related to BroadleafCommerce/QA#738
1 parent 8684c3d commit 43b4cf4

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

admin/broadleaf-open-admin-platform/src/main/java/org/broadleafcommerce/openadmin/web/rulebuilder/dto/FieldData.java

+18
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class FieldData {
3838
protected String options;
3939
protected SupportedFieldType fieldType;
4040
protected SupportedFieldType secondaryFieldType;
41+
protected boolean skipValidation;
4142

4243
private FieldData(Builder builder) {
4344
this.fieldLabel = builder.fieldLabel;
@@ -46,6 +47,7 @@ private FieldData(Builder builder) {
4647
this.options = builder.options;
4748
this.fieldType = builder.fieldType;
4849
this.secondaryFieldType = builder.secondaryFieldType;
50+
this.skipValidation = builder.skipValidation;
4951
}
5052

5153
public static class Builder {
@@ -55,6 +57,7 @@ public static class Builder {
5557
protected String options = null;
5658
protected SupportedFieldType fieldType = null;
5759
protected SupportedFieldType secondaryFieldType = null;
60+
protected boolean skipValidation;
5861

5962
public FieldData build() {
6063
return new FieldData(this);
@@ -91,6 +94,11 @@ public Builder secondaryType(SupportedFieldType fieldType) {
9194
this.secondaryFieldType = fieldType;
9295
return this;
9396
}
97+
98+
public Builder skipValidation(boolean skipValidation) {
99+
this.skipValidation = skipValidation;
100+
return this;
101+
}
94102
}
95103

96104
public String getFieldLabel() {
@@ -116,4 +124,14 @@ public SupportedFieldType getFieldType() {
116124
public SupportedFieldType getSecondaryFieldType() {
117125
return secondaryFieldType;
118126
}
127+
128+
public boolean getSkipValidation() {
129+
return skipValidation;
130+
}
131+
132+
public void setSkipValidation(boolean skipValidation) {
133+
this.skipValidation = skipValidation;
134+
}
135+
136+
119137
}

admin/broadleaf-open-admin-platform/src/main/java/org/broadleafcommerce/openadmin/web/rulebuilder/service/AbstractRuleBuilderFieldService.java

+18-16
Original file line numberDiff line numberDiff line change
@@ -174,22 +174,24 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl
174174
}
175175

176176
private void testFieldName(FieldData fieldData) throws ClassNotFoundException {
177-
if (!StringUtils.isEmpty(fieldData.getFieldName()) && dynamicEntityDao != null) {
178-
Class<?>[] dtos = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(Class.forName(getDtoClassName()));
179-
if (ArrayUtils.isEmpty(dtos)) {
180-
dtos = new Class<?>[]{Class.forName(getDtoClassName())};
181-
}
182-
Field field = null;
183-
for (Class<?> dto : dtos) {
184-
field = dynamicEntityDao.getFieldManager().getField(dto, fieldData.getFieldName());
185-
if (field != null) {
186-
break;
187-
}
188-
}
189-
if (field == null) {
190-
throw new IllegalArgumentException("Unable to find the field declared in FieldData (" + fieldData.getFieldName() + ") on the target class (" + getDtoClassName() + "), or any registered entity class that derives from it.");
191-
}
192-
}
177+
if (! fieldData.getSkipValidation()) {
178+
if (!StringUtils.isEmpty(fieldData.getFieldName()) && dynamicEntityDao != null) {
179+
Class<?>[] dtos = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(Class.forName(getDtoClassName()));
180+
if (ArrayUtils.isEmpty(dtos)) {
181+
dtos = new Class<?>[]{Class.forName(getDtoClassName())};
182+
}
183+
Field field = null;
184+
for (Class<?> dto : dtos) {
185+
field = dynamicEntityDao.getFieldManager().getField(dto, fieldData.getFieldName());
186+
if (field != null) {
187+
break;
188+
}
189+
}
190+
if (field == null) {
191+
throw new IllegalArgumentException("Unable to find the field declared in FieldData (" + fieldData.getFieldName() + ") on the target class (" + getDtoClassName() + "), or any registered entity class that derives from it.");
192+
}
193+
}
194+
}
193195
}
194196
});
195197
this.fields = proxyFields;

0 commit comments

Comments
 (0)