#683 Add activity constraints - #684
Conversation
UmlToCifTranslator: translate activity requirements
|
Documentation to be updated as well. |
| } | ||
|
|
||
| // Translate activity requirements. | ||
| for (Constraint umlConstraint: activity.getOwnedRules()) { |
There was a problem hiding this comment.
Is it sufficient to translate the requirements like this? Should we also include all requirements of other activities that we call, etc? (all other 'relevant' activities)
There was a problem hiding this comment.
I did this to be consistent with the occurrence constraints: these are considered only during the activity synthesis, not when an activity is called. Better to have a conversation offline about this.
There was a problem hiding this comment.
Did we ever discuss this? Was there a conclusion?
| return constraint.getContext() instanceof PrimitiveType; | ||
| } | ||
|
|
||
| public static boolean isActivityRequirement(Constraint constraint) { |
There was a problem hiding this comment.
Move isActivityRequirement to just after isActivityPostconditionConstraint.
| return constraint.getContext() instanceof PrimitiveType; | ||
| } | ||
|
|
||
| public static boolean isActivityRequirement(Constraint constraint) { |
There was a problem hiding this comment.
Rename isActivityRequirement to isActivityRequirementConstraint, to match other methods?
|
|
||
| public static boolean isActivityRequirement(Constraint constraint) { | ||
| return constraint.getContext() instanceof Activity activity | ||
| // It is the correct type of constraint. |
There was a problem hiding this comment.
Can't we check that it is a FormalConstraint?
There was a problem hiding this comment.
It was my first choice, but I then wrote it this way to be consistent with the rest of the class and structure that we have e.g., in the validator. To be honest, if I write a isRequirementConstraint method in PokaYokeUmlProfileUtil, this method in CifContext is not needed at all. But it will not be consistent with the rest of validation, for instance.
I will remove this method and add a new one in PokaYokeUmlProfileUtil, and let's see how it looks. I think it looks better; but if consistency with the rest is more important we can revert back to this.
There was a problem hiding this comment.
Rename to isClassRequirementConstraint?
| .filter(r -> CifContext.isActivityRequirement(r)).map(Constraint.class::cast) | ||
| .collect(Collectors.toCollection(LinkedHashSet::new)); | ||
|
|
||
| if (!members.equals(Sets.union(Sets.union(preAndPostconditions, intervalConstraints), activityRequirements))) { |
There was a problem hiding this comment.
I think Sets.union supports also giving 3 sets instead of 2, right?
There was a problem hiding this comment.
Not sure how to make it work, so I created a set union with stream.
| checkValidActivityPrePostconditionConstraint(constraint); | ||
| } else if (CifContext.isClassConstraint(constraint)) { | ||
| checkValidClassConstraint(constraint); | ||
| } else if (CifContext.isClassConstraint(constraint) || (CifContext.isActivityRequirement(constraint))) { |
There was a problem hiding this comment.
Does it still make sense to have CifContext.isClassConstraint? Should we rename it to CifContext.isClassRequirementConstraint?
There was a problem hiding this comment.
See previous comments.
| } | ||
|
|
||
| private void checkValidClassConstraint(Constraint constraint) { | ||
| private void checkValidClassOrActivityConstraint(Constraint constraint) { |
There was a problem hiding this comment.
This is only requirements, from classes and activities, right? So, maybe rename to checkValidRequirementConstraint?
There was a problem hiding this comment.
Why check this with a global scope? Why not in the scope of the activity, if it is in an activity?
|
Does editing these new constraints with the SynthML tab work? |
| @@ -529,7 +528,7 @@ public static List<Stereotype> getSupportedConstraintStereotypes(Constraint cons | |||
| } else if (isPostconditionConstraint(constraint)) { | |||
| return List.of(getStereotype(constraint, ST_POSTCONDITION)); | |||
| } else if (isClassRequirement(constraint)) { | |||
There was a problem hiding this comment.
I always forget that Activity inherits from Class. Super non-intuitive. I'd maybe rename the method to isClassOrActivityRequirementConstraint, and there add a comment in the body like // Note that 'Activity' inherits from 'Class'. or so?
Co-authored-by: Dennis Hendriks <dh_tue@hotmail.com>
UmlToCifTranslator, FlattenUmlActivity: rename methods
- make methods public - add occurrence constraint and primitive type constraint methods PokaYokeProfileValidator: use the new methods
UmlToCameoTransformer, Uml2GalTranslator, PokaYokeProfileValidator: use the PokaYokeUmlProfileUtil method
AbstractActivityDependencyOrderer: use the PokaYokeUmlProfileUtil method
constraint PokaYokeProfileValidator: use the PokaYokeUmlProfileUtil methods
|
Ready for review, best commit-by-commit. |
| */ | ||
| private boolean isBlockingOccurrenceConstraint(Constraint constraint) { | ||
| if (CifContext.isOccurrenceConstraint(constraint)) { | ||
| if (PokaYokeUmlProfileUtil.isContainedAsActivityOccurrenceConstraint(constraint)) { |
There was a problem hiding this comment.
I'd have expected here isOccurrenceConstraint, not the containment variant. (see also other comment)
|
|
||
| private static boolean isPreconditionConstraint(Constraint constraint) { | ||
| public static boolean isContainedAsActivityPrecondition(Constraint constraint) { | ||
| return (constraint.eContainer() instanceof Activity activity) |
There was a problem hiding this comment.
Remove unnecessary parentheses like in isContainedAsClassOrActivityOwnedRule.
|
|
||
| public static boolean isSynthesisPrecondition(Constraint constraint) { | ||
| public static boolean isContainedAsActivityPostcondition(Constraint constraint) { | ||
| return (constraint.eContainer() instanceof Activity activity) |
There was a problem hiding this comment.
Remove unnecessary parentheses like in isContainedAsClassOrActivityOwnedRule.
|
|
||
| public static boolean isContainedAsClassOrActivityOwnedRule(Constraint constraint) { | ||
| // Activity is a sub-type of Classifier. | ||
| return constraint.eContainer() instanceof Classifier clazz && clazz.getOwnedRules().contains(constraint); |
There was a problem hiding this comment.
Why do we check for Classifier and not Class? Not saying it is wrong. Just wondering which is better?
| } | ||
|
|
||
| public static boolean isContainedAsClassOrActivityOwnedRule(Constraint constraint) { | ||
| // Activity is a sub-type of Classifier. |
There was a problem hiding this comment.
// Activity is a sub-type of Classifier. -> // 'Activity' is a sub-type of 'Class'. (if we go check for being a class) or // 'Activity' is a sub-type of 'Class', which is a sub-type of 'Classifier'. (if we keep the code as is).
| return (constraint.eContainer() instanceof Activity activity) | ||
| && activity.getPostconditions().contains(constraint); | ||
| } | ||
| public static boolean isRequirementConstraint(Constraint constraint) { |
There was a problem hiding this comment.
I miss here isOccurrenceConstraint that checks the stereotype, like this and similar methods. We seem to only have the containment one for occurrence constraints.
| .flatMap(Set::stream).collect(Collectors.toSet()); | ||
|
|
||
| if (!members.equals(allowedMembers)) { | ||
| error("Activity should contain only precondition, postcondition, constraints and interval constraint members.", |
There was a problem hiding this comment.
| error("Activity should contain only precondition, postcondition, constraints and interval constraint members.", | |
| error("Activity should contain only precondition, postcondition, requirement and interval constraints as members.", |
| } else if (PokaYokeUmlProfileUtil.isContainedAsActivityOccurrenceConstraint(constraint)) { | ||
| checkValidOccurrenceConstraint((IntervalConstraint)constraint); | ||
| } else if (PokaYokeUmlProfileUtil.isRequirementConstraint(constraint)) { | ||
| // Check the class and activity requirements. |
There was a problem hiding this comment.
| // Check the class and activity requirements. | |
| // Check the class or activity requirement. |
It is either one of them, not both. It is also only one requirement, I think.
Should still be done then. |
Should not forget this. |
|
Thanks for the review. I would prefer to finish vertical scaling and then finish this PR. just to avoid confusion. |




Closes #683.
I will add a regression test once the changes are approved.