Skip to content

Commit

Permalink
FIPS-10343/FIPS-11500 :: Mandatory attribute cannot become irrelevant…
Browse files Browse the repository at this point in the history
… in product

Change-Id: I8d48e5201fd899192d0e577755312a3366b246f9
  • Loading branch information
lara0905 committed May 3, 2024
1 parent 99beeed commit 5a4814f
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ private void initControls() {
if (!valueSet.isEmpty()) {
options.put(AttributeRelevance.Mandatory, Messages.AttributeRelevanceControl_Mandatory);
}
if (!valueDatatype.isPrimitive() && valueSet.isContainsNull()) {
options.put(AttributeRelevance.Optional, Messages.AttributeRelevanceControl_Optional);
if (valueSet.isContainsNull()) {
if (!valueDatatype.isPrimitive()) {
options.put(AttributeRelevance.Optional, Messages.AttributeRelevanceControl_Optional);
}
options.put(AttributeRelevance.Irrelevant, Messages.AttributeRelevanceControl_Irrelevant);
}
options.put(AttributeRelevance.Irrelevant, Messages.AttributeRelevanceControl_Irrelevant);
radioButtonGroup = toolkit.createRadioButtonGroup(this, options);
initLayout(options.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ protected void validateContent(MessageList list, IIpsProject ipsProject, IPolicy

if (modelValueSet.validate(ipsProject).containsErrorMsg()) {
String text = Messages.ConfiguredValueSet_msgInvalidAttributeValueset;
list.add(new Message(IConfiguredValueSet.MSGCODE_UNKNWON_VALUESET, text, Message.WARNING, this,
list.add(new Message(IConfiguredValueSet.MSGCODE_UNKNOWN_VALUESET, text, Message.WARNING, this,
PROPERTY_VALUE_SET));
return;
}
Expand All @@ -110,12 +110,20 @@ protected void validateContent(MessageList list, IIpsProject ipsProject, IPolicy
list.add(new Message("", text, Message.ERROR, this, PROPERTY_VALUE_SET)); //$NON-NLS-1$
return;
}
if (valueSetToValidate.isEnum() && modelValueSet.isStringLength()) {
MessageList valueValidationResult = validateEnumValueStringLength(ipsProject,
(IEnumValueSet)valueSetToValidate,
(IStringLengthValueSet)modelValueSet);
if (!valueValidationResult.isEmpty()) {
list.add(valueValidationResult);
if (valueSetToValidate.isEnum()) {
if (modelValueSet.isStringLength()) {
MessageList valueValidationResult = validateEnumValueStringLength(ipsProject,
(IEnumValueSet)valueSetToValidate,
(IStringLengthValueSet)modelValueSet);
if (!valueValidationResult.isEmpty()) {
list.add(valueValidationResult);
return;
}

}
if (valueSetToValidate.isEmpty() && !modelValueSet.isContainsNull()) {
String text = Messages.ConfiguredValueSet_error_msg_mandatoryAttribute;
list.add(new Message(MSGCODE_MANDATORY_VALUESET_IS_EMPTY, text, Message.ERROR, this, PROPERTY_VALUE_SET)); //$NON-NLS-1$
return;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ private Messages() {
public static String ConfiguredValueSet_msgInvalidAttributeValueset;
public static String ConfiguredDefault_caption;
public static String ConfiguredValueSet_caption;
public static String ConfiguredValueSet_error_msg_mandatoryAttribute;

public static String Formula_msgExpressionMissing;
public static String Formula_msgFormulaSignatureMissing;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ConfiguredDefault_msgValueNotParsable=The value {0} is not a {1}.

ConfiguredValueSet_caption={0}Value set of {1}
ConfiguredValueSet_error_msg_abstractValueSet=Must specify a concrete set of values\!
ConfiguredValueSet_error_msg_mandatoryAttribute=The attribute is marked as mandatory in the model. The value set must contain at least one value.
ConfiguredValueSet_msgInvalidAttributeValueset=This value set configuration element can not be validated against the value set of the attribute, because the value set of the attribute is not valid.

DateBasedProductCmptNamingStrategy_msgWrongFormat=The {0} identification has the wrong format\. Expected format: {1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ public interface IConfiguredValueSet extends IConfigElement, IValueSetOwner {
* Validation message code to indicate that the value-set of the attribute (in the model) is
* invalid.
*/
String MSGCODE_UNKNWON_VALUESET = MSGCODE_PREFIX + "InvalidAttirbuteValueSet"; //$NON-NLS-1$
String MSGCODE_UNKNOWN_VALUESET = MSGCODE_PREFIX + "InvalidAttirbuteValueSet"; //$NON-NLS-1$

/**
* Validation message code to indicate that the config elements value set is empty while the
* value set defined in the model is mandatory.
*/
String MSGCODE_MANDATORY_VALUESET_IS_EMPTY = MSGCODE_PREFIX + "MandatoryValueSetIsEmpty"; //$NON-NLS-1$

/**
* Validation message code to indicate that a string is too long to fit into the value set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ ConfiguredDefault_msgValueNotParsable=Der Wert {0} ist kein {1}.

ConfiguredValueSet_caption={0}Wertemenge {1}
ConfiguredValueSet_error_msg_abstractValueSet=Es muss eine konkrete Wertemenge angegeben werden.
ConfiguredValueSet_error_msg_mandatoryAttribute=Das Attribut ist ein Pflichtattribut. Die Wertemenge muss mindestens einen Wert enthalten.
ConfiguredValueSet_msgInvalidAttributeValueset=Der Wertebereich und der Wert dieses Konfigurationselements kann nicht gegen den Wertebereich des Attributs gepr\u00FCft werden, da der Wertebereich des Attributs nicht g\u00FCltig ist.

DateBasedProductCmptNamingStrategy_msgWrongFormat=Die {0}-Id hat ein falsche Format. Erwartetes Format\: {1}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,16 @@ public void testValidate_InvalidDatatype() throws Exception {
}
}

@Test
public void testValidate_MandatoryValueSetIsEmpty() {
configuredValueSet.changeValueSetType(ValueSetType.ENUM);
attribute.setDatatype("Integer");
attribute.getValueSet().setContainsNull(false);

MessageList ml = configuredValueSet.validate(ipsProject);
assertThat(ml, hasMessageCode(IConfiguredValueSet.MSGCODE_MANDATORY_VALUESET_IS_EMPTY));
}

@Test
public void testValidate_ValueSetTypeMismatch() {
setUpRangeIntegerAttr();
Expand Down Expand Up @@ -332,6 +342,7 @@ public void testValidate_ValueSetTypeMismatchForUndefinedValues() {

private void setUpRangeIntegerAttr() {
attribute.setValueSetType(ValueSetType.RANGE);
attribute.getValueSet().setContainsNull(true);
attribute.setDatatype("Integer");
}

Expand Down

0 comments on commit 5a4814f

Please sign in to comment.