Skip to content

Commit

Permalink
Merge pull request #42 from OP-TED/feature/TEDEFO-2740-check-noticety…
Browse files Browse the repository at this point in the history
…pes-duplicates

fields: Check noticeTypes properties have no duplicates (TEDEFO-2740)
  • Loading branch information
bertrand-lorentz authored Nov 7, 2023
2 parents 7b42952 + b44751c commit cacabd6
Show file tree
Hide file tree
Showing 6 changed files with 3,418 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -64,6 +65,18 @@ public Set<String> getAllNoticeTypeIds() {
.collect(Collectors.toSet());
}

public Set<String> getDuplicateNoticeTypeIds() {
List<String> values = getConstraints()
.stream()
.map(AbstractConstraint::getNoticeTypes)
.flatMap(List::stream)
.collect(Collectors.toList());

return values.stream()
.filter(i -> Collections.frequency(values, i) > 1)
.collect(Collectors.toSet());
}

/**
* @return All label identifiers referenced in the constraints of this field property.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,23 @@ public Set<String> getAllNoticeTypes() {
return noticeTypes;
}

/**
* Return the notices types that appear more than once in the same property.
*/
public Set<String> getDuplicateNoticeTypes() {
Set<String> noticeTypes = new HashSet<>();

// Go over all dynamic properties and collect duplicate notice types
getDynamicProperties()
.forEach(property -> {
if (property != null) {
noticeTypes.addAll(property.getDuplicateNoticeTypeIds());
}
});

return noticeTypes;
}

public String getPrivacyCode() {
if (field.getPrivacy() != null) {
return field.getPrivacy().getCode().getLiteral();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,10 @@ when
then
results.add(new ValidationResult($f, "SchemeName does not match preset value of a corresponding attribute field", ValidationStatusEnum.ERROR));
end

rule "Field constraints do not have duplicate notice types identifiers"
when
/fields[ $f: this, $duplicateNoticeTypes: duplicateNoticeTypes, $duplicateNoticeTypes.size() > 0 ]
then
results.add(new ValidationResult($f, "At least one constraint has duplicate notice types :" + $duplicateNoticeTypes, ValidationStatusEnum.ERROR));
end
Loading

0 comments on commit cacabd6

Please sign in to comment.