Skip to content

Commit

Permalink
FIPS-10909/FIPS-11520 :: Merge branch 'FIPS-10909' into main : Overri…
Browse files Browse the repository at this point in the history
…ding of validation rules

Change-Id: I683d7cb5dba22289eba7841dac9313db0accc74c
  • Loading branch information
hd42 committed May 16, 2024
2 parents 5ebf640 + c597a7b commit 555035b
Show file tree
Hide file tree
Showing 39 changed files with 859 additions and 237 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
</xsd:attribute>
<xsd:attributeGroup ref="modifier" />
<xsd:attribute name="name" type="string" use="required" />
<xsd:attribute name="overriding" type="boolean" use="optional" />
<xsd:attributeGroup ref="since" />
<xsd:attribute name="validatedAttrSpecifiedInSrc" type="boolean" use="optional" />
</xsd:complexType>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ private Messages() {
public static String RuleEditDialog_contains;
public static String RuleEditDialog_labelCode;
public static String RuleEditDialog_labelName;
public static String RuleEditDialog_overwritesNote;
public static String RuleEditDialog_labelCategory;
public static String RuleEditDialog_labelSeverity;
public static String RuleEditDialog_labelSpecifiedInSrc;
Expand All @@ -319,4 +320,7 @@ private Messages() {

public static String RuleEditDialog_groupText;

public static String OverrideValidationRuleDialog_labelNoAttributes;
public static String OverrideValidationRuleDialog_labelSelectAttribute;
public static String OverrideValidationRuleDialog_title;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*******************************************************************************
* Copyright (c) Faktor Zehn GmbH - faktorzehn.org
*
*
* This source code is available under the terms of the AGPL Affero General Public License version
* 3.
*
*
* Please see LICENSE.txt for full license terms, including the additional permissions and
* restrictions as well as the possibility of alternative license terms.
*******************************************************************************/
Expand All @@ -14,6 +14,7 @@

import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IWorkbenchPartSite;
Expand All @@ -23,6 +24,7 @@
import org.faktorips.devtools.core.ui.editors.EditDialog;
import org.faktorips.devtools.core.ui.editors.IpsPartsComposite;
import org.faktorips.devtools.core.ui.editors.SimpleIpsPartsSection;
import org.faktorips.devtools.core.ui.editors.pctype.rule.OverrideRuleDialog;
import org.faktorips.devtools.core.ui.editors.pctype.rule.RuleEditDialog;
import org.faktorips.devtools.model.ipsobject.IIpsObject;
import org.faktorips.devtools.model.ipsobject.IIpsObjectPart;
Expand Down Expand Up @@ -66,7 +68,7 @@ private class RulesComposite extends IpsPartsComposite {

RulesComposite(IIpsObject pdObject, Composite parent, UIToolkit toolkit) {
super(pdObject, parent, getSite(), EnumSet.of(Option.CAN_CREATE, Option.CAN_EDIT, Option.CAN_DELETE,
Option.CAN_MOVE, Option.SHOW_EDIT_BUTTON, Option.JUMP_TO_SOURCE_CODE_SUPPORTED,
Option.CAN_MOVE, Option.CAN_OVERRIDE, Option.SHOW_EDIT_BUTTON, Option.JUMP_TO_SOURCE_CODE_SUPPORTED,
Option.RENAME_REFACTORING_SUPPORTED), toolkit);

}
Expand Down Expand Up @@ -102,6 +104,15 @@ protected int[] moveParts(int[] indexes, boolean up) {
return getPcType().moveRules(indexes, up);
}

@Override
public void overrideClicked() {
OverrideRuleDialog dialog = new OverrideRuleDialog(getPcType(), getShell());
if (dialog.open() == Window.OK) {
getPcType().overrideValidationRules(dialog.getSelectedParts());
refresh();
}
}

private class ContentProvider implements IStructuredContentProvider {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ RuleEditDialog_title=Edit Validation Rule
RuleEditDialog_generalTitle=General
RuleEditDialog_attrTitle=Validated Attributes
RuleEditDialog_labelName=Name:
RuleEditDialog_overwritesNote=\ Overrides a rule from a supertype
RuleEditDialog_labelCategory=Category:
RuleEditDialog_messageGroupTitle=Message
RuleEditDialog_labelCode=Code:
Expand Down Expand Up @@ -178,4 +179,7 @@ AssociationQualificationGroup_labelIsQualifiedByType=\ by type "{0}"
AssociationQualificationGroup_labelNoteQualificationOnlyTargetConfByProduct=Qualification is only applicable, if the target type is configurable by a product.
AssociationQualificationGroup_noteQualifiedMultiplictyPerQualifiedInstance=For qualified associations multiplicity is defined per qualified instance.
AssociationQualificationGroup_noteIsNotConstrained=Note: This association is not constrained by product structure.
AssociationEditDialog_constrain=Overrides an association of a supertype
AssociationEditDialog_constrain=Overrides an association of a supertype
OverrideValidationRuleDialog_title=Override Validation Rules
OverrideValidationRuleDialog_labelNoAttributes=No validation rules available.
OverrideValidationRuleDialog_labelSelectAttribute=Select validation rules to override:
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*******************************************************************************
* Copyright (c) Faktor Zehn GmbH - faktorzehn.org
*
* This source code is available under the terms of the AGPL Affero General Public License version
* 3.
*
* Please see LICENSE.txt for full license terms, including the additional permissions and
* restrictions as well as the possibility of alternative license terms.
*******************************************************************************/

package org.faktorips.devtools.core.ui.editors.pctype.rule;

import java.util.List;

import org.eclipse.swt.widgets.Shell;
import org.faktorips.devtools.core.ui.editors.SelectSupertypeHierarchyPartsDialog;
import org.faktorips.devtools.core.ui.editors.SupertypeHierarchyPartsContentProvider;
import org.faktorips.devtools.core.ui.editors.pctype.Messages;
import org.faktorips.devtools.model.ipsobject.IIpsObject;
import org.faktorips.devtools.model.ipsobject.IIpsObjectPart;
import org.faktorips.devtools.model.pctype.IPolicyCmptType;
import org.faktorips.devtools.model.pctype.IValidationRule;

/**
* A dialog that enables the user to select {@link IValidationRule validation rules} to overwrite.
*/
public class OverrideRuleDialog extends SelectSupertypeHierarchyPartsDialog<IValidationRule> {

/**
* @param policyCmptType The {@link IPolicyCmptType policy component type} to get the candidates to possibly overwrite from.
* @param parent The {@link Shell} to show this dialog in.
*/
public OverrideRuleDialog(IPolicyCmptType policyCmptType, Shell parent) {
super(parent, new CandidatesContentProvider(policyCmptType));
setTitle(Messages.OverrideValidationRuleDialog_title);
setEmptyListMessage(Messages.OverrideValidationRuleDialog_labelNoAttributes);
setSelectLabelText(Messages.OverrideValidationRuleDialog_labelSelectAttribute);
}

/** Provides the {@link IValidationRule validation rules} available for selection. */
private static class CandidatesContentProvider extends SupertypeHierarchyPartsContentProvider {

/**
* @param policyCmptType The {@link IPolicyCmptType policy component type} the {@link IValidationRule validation rules} available for
* selection belong to.
*/
public CandidatesContentProvider(IPolicyCmptType policyCmptType) {
super(policyCmptType);
}

@Override
public List<? extends IIpsObjectPart> getAvailableParts(IIpsObject ipsObject) {
IPolicyCmptType policyCmptType = (IPolicyCmptType)ipsObject;
return policyCmptType.findOverrideValidationRuleCandidates(policyCmptType.getIpsProject());
}

@Override
protected List<? extends IIpsObject> getSupertypes(IIpsObject ipsObject) {
IPolicyCmptType policyCmptType = (IPolicyCmptType)ipsObject;
return policyCmptType.getSupertypeHierarchy().getAllSupertypes(policyCmptType);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public class ValidationRuleEditingUI {

private CharCountPainter charCountPainter;
private TextField nameField;
private Checkbox overwritesCheckbox;
private TextField msgCodeField;
private EnumField<MessageSeverity> msgSeverityField;
private TextField msgTextField;
Expand Down Expand Up @@ -208,6 +209,8 @@ private void createGeneralGroup(Composite workArea) {
nameText.setFocus();
nameField = new TextField(nameText);

overwritesCheckbox = new Checkbox(generalGroup, uiToolkit);
overwritesCheckbox.setText(Messages.RuleEditDialog_overwritesNote);
}

private void updateCharCount() {
Expand All @@ -226,6 +229,8 @@ private void updateCharCount() {
*/
public void bindFields(IValidationRule rule, BindingContext bindingContext) {
bindingContext.bindContent(nameField, rule, IValidationRule.PROPERTY_NAME);
bindingContext.bindEnabled(nameField.getTextControl(), rule, IValidationRule.PROPERTY_OVERRIDING, false);
bindingContext.bindContent(overwritesCheckbox, rule, IValidationRule.PROPERTY_OVERRIDING);
bindingContext.bindContent(msgSeverityField, rule, IValidationRule.PROPERTY_MESSAGE_SEVERITY);
final InternationalStringPresentationObject msgTextPMO = new InternationalStringPresentationObject(
rule.getMessageText());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

package org.faktorips.devtools.core.ui.editors.productcmpttype;

import static org.faktorips.devtools.model.internal.productcmpttype.ProductCmptCategory.isOverriding;

import java.io.DataInput;
import java.io.DataOutput;
import java.util.ArrayList;
Expand Down Expand Up @@ -64,7 +66,6 @@
import org.faktorips.devtools.model.IIpsElement;
import org.faktorips.devtools.model.IIpsModel;
import org.faktorips.devtools.model.decorators.OverlayIcons;
import org.faktorips.devtools.model.internal.productcmpttype.ProductCmptCategory;
import org.faktorips.devtools.model.ipsobject.IIpsSrcFile;
import org.faktorips.devtools.model.ipsobject.IpsObjectType;
import org.faktorips.devtools.model.ipsobject.QualifiedNameType;
Expand Down Expand Up @@ -318,7 +319,7 @@ protected void updateButtonEnabledStates() {
boolean isMovable = categorySection.isContextTypeEditable()
&& isPropertySelected()
&& isPropertyOfContextTypeSelected()
&& !ProductCmptCategory.isOwerwriting(getSelectedProperty());
&& !isOverriding(getSelectedProperty());
moveUpButton.setEnabled(isMovable && !isFirstLocalPropertyOfContextTypeSelected());
moveDownButton.setEnabled(isMovable && !isLastPropertyOfContextTypeSelected());
changeCategoryButton.setEnabled(isSelectedPropertyAllowedToChangeCategory());
Expand All @@ -332,7 +333,7 @@ private IProductCmptProperty getFirstLocalPropertyOfContextType() {
for (Object o : contentProvider.getElements(null)) {
if (o instanceof IProductCmptProperty p
&& isPropertyOfContextType(p)
&& !ProductCmptCategory.isOwerwriting(p)) {
&& !isOverriding(p)) {
return (IProductCmptProperty)o;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private void initializeOverwritingAttributesList() {
overwritingAttributes = new ArrayList<>();
List<? extends IAttribute> ipsObjectParts = getIpsObjectParts(getParentIpsElement());
for (IAttribute attribute : ipsObjectParts) {
if (attribute.isOverwrite()) {
if (attribute.isOverriding()) {
overwritingAttributes.add(getContext().getLabel(attribute));
}
}
Expand All @@ -58,7 +58,7 @@ protected boolean showObjectPart(IAttribute objectPart) {
if (overwritingAttributes.contains(getContext().getLabel(objectPart))) {
return false;
}
if (objectPart.isOverwrite()) {
if (objectPart.isOverriding()) {
overwritingAttributes.add(getContext().getLabel(objectPart));
}
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected List<String> getAttributeData(IAttribute attribute) {

attributeData.add(polAttribute.isProductRelevant() ? "X" : "-"); //$NON-NLS-1$ //$NON-NLS-2$
attributeData.add(polAttribute.getAttributeType().getName());
attributeData.add(polAttribute.isOverwrite() ? "X" : "-"); //$NON-NLS-1$ //$NON-NLS-2$
attributeData.add(polAttribute.isOverriding() ? "X" : "-"); //$NON-NLS-1$ //$NON-NLS-2$

return attributeData;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*******************************************************************************
* Copyright (c) Faktor Zehn GmbH - faktorzehn.org
*
*
* This source code is available under the terms of the AGPL Affero General Public License version
* 3.
*
*
* Please see LICENSE.txt for full license terms, including the additional permissions and
* restrictions as well as the possibility of alternative license terms.
*******************************************************************************/
Expand All @@ -24,7 +24,8 @@ public class ValidationRuleAnnGen implements IAnnotationGenerator {
public JavaCodeFragment createAnnotation(AbstractGeneratorModelNode modelNode) {
XValidationRule xValidationRule = (XValidationRule)modelNode;
String name = xValidationRule.getName();
String msgCode = xValidationRule.getConstantNameMessageCode();
String msgCode = xValidationRule.getQualifierForConstantNameMessageCodeIfNecessary()
+ xValidationRule.getConstantNameMessageCode();
String severityJavaCode = xValidationRule.getSeverityConstant();

JavaCodeFragmentBuilder annotationLn = new JavaCodeFragmentBuilder().annotationLn(IpsValidationRule.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

import org.faktorips.codegen.DatatypeHelper;
import org.faktorips.codegen.JavaCodeFragment;
Expand Down Expand Up @@ -67,6 +69,21 @@ public boolean isCheckValueAgainstValueSetRule() {
return getValidationRule().isCheckValueAgainstValueSetRule();
}

public boolean isOverwrite() {
return getValidationRule().isOverriding();
}

public boolean isDifferentMessageCodeInOverridingRule() {
return isOverwrite() && !Objects.equals(getOverwrittenRuleNode().getMessageCode(), getMessageCode());
}

public boolean isSignatureChanged() {
if (!isOverwrite()) {
return false;
}
return getOverwrittenRuleNode().getCreateMessageParameters().size() != getCreateMessageParameters().size();
}

public XPolicyAttribute getCheckedAttribute() {
IAttribute attr = getValidationRule().getType().getAttribute(getValidationRule().getValidatedAttributeAt(0));
return getModelNode(attr, XPolicyAttribute.class);
Expand All @@ -84,6 +101,28 @@ public LinkedHashSet<String> getReplacementParameters() {
return convertToJavaParameters(getValidationRule().getMessageText().getReplacementParameters());
}

public String getReplacementParametersForOverwrittingRule() {
LinkedHashSet<String> superReplacementParameters = getOverwrittenRuleNode().getReplacementParameters();
LinkedHashSet<String> replacementParameters = getReplacementParameters();
if (replacementParameters.isEmpty()) {
return "";
}
ArrayList<String> parameters = new ArrayList<>();
for (String replacementParameter : replacementParameters) {
if (superReplacementParameters.contains(replacementParameter)) {
parameters.add("message.getReplacementValue(\"" + replacementParameter + "\")");
} else {
parameters.add("null");
}
}
return parameters.stream().collect(Collectors.joining(" ,", " ,", ""));
}

private XValidationRule getOverwrittenRuleNode() {
IValidationRule overwrittenRule = getValidationRule().findOverwrittenValidationRule(getIpsProject());
return getModelNode(overwrittenRule, getClass());
}

public String getDefaultLocale() {
ISupportedLanguage defaultLanguage = getIpsProject().getReadOnlyProperties().getDefaultLanguage();
JavaCodeFragment localeCodeFragment = LocaleGeneratorUtil.getLocaleCodeFragment(defaultLanguage.getLocale());
Expand Down Expand Up @@ -148,6 +187,16 @@ public String getConstantNameMessageCode() {
return "MSG_CODE_" + upperCaseName;
}

public String getQualifierForConstantNameMessageCodeIfNecessary() {
if (isOverwrite() && getGeneratorConfig().isGeneratePublishedInterfaces(getIpsProject())) {
XPolicyCmptClass xPolicyCmptClass = getModelService()
.getModelNode(getIpsObjectPartContainer().getIpsObject(), XPolicyCmptClass.class, getContext());
return xPolicyCmptClass.getInterfaceName() + '.';
} else {
return "";
}
}

public String getMessageCode() {
return getValidationRule().getMessageCode();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*******************************************************************************
* Copyright (c) Faktor Zehn GmbH - faktorzehn.org
*
*
* This source code is available under the terms of the AGPL Affero General Public License version
* 3.
*
*
* Please see LICENSE.txt for full license terms, including the additional permissions and
* restrictions as well as the possibility of alternative license terms.
*******************************************************************************/
Expand Down Expand Up @@ -40,6 +40,9 @@ public ImageDescriptor getImageDescriptor(IIpsElement ipsElement) {
overlays[IDecoration.TOP_LEFT] = OverlayIcons.STATIC;
}
}
if (rule.isOverriding()) {
overlays[IDecoration.BOTTOM_RIGHT] = OverlayIcons.OVERRIDE;
}
if (rule.isDeprecated()) {
overlays[IDecoration.BOTTOM_LEFT] = OverlayIcons.DEPRECATED;
}
Expand All @@ -54,7 +57,7 @@ public ImageDescriptor getImageDescriptor(IIpsElement ipsElement) {

/**
* {@inheritDoc}
*
*
* If the given {@link IIpsElement} is an {@link IValidationRule}, this method returns the
* validation rule's label.
*/
Expand Down

0 comments on commit 555035b

Please sign in to comment.