Skip to content

Commit cd52354

Browse files
Merge pull request #45 from OwnYourData/disable-multi-attribute-definition
Throw exception if attribute is defined by multiple objects
2 parents 6872119 + 12878bd commit cd52354

1 file changed

Lines changed: 9 additions & 9 deletions

File tree

src/main/java/com/example/anonymization/service/ConfigurationService.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@
1919
import java.net.http.HttpClient;
2020
import java.net.http.HttpRequest;
2121
import java.net.http.HttpResponse;
22-
import java.util.HashMap;
23-
import java.util.Map;
24-
import java.util.Set;
22+
import java.util.*;
2523

2624
@Service
2725
public class ConfigurationService {
@@ -48,12 +46,7 @@ public static Map<Resource, Map<Property, Configuration>> fetchConfigForObjects(
4846
public static Map<Property, Configuration> createFlatConfig(Map<Resource, Map<Property, Configuration>> configs) {
4947
Map<Property, Configuration> flatConfig = new HashMap<>();
5048
for (Map<Property, Configuration> configMap : configs.values()) {
51-
for (Map.Entry<Property, Configuration> entry : configMap.entrySet()) {
52-
if (flatConfig.containsKey(entry.getKey())) {
53-
throw new OntologyException("Duplicate Property key found in Flat Ontology: " + entry.getKey());
54-
}
55-
flatConfig.put(entry.getKey(), entry.getValue());
56-
}
49+
flatConfig.putAll(configMap);
5750
}
5851
return flatConfig;
5952
}
@@ -107,8 +100,15 @@ private static String fetchStringContent(String url) {
107100
@NotNull
108101
private static Map<Resource, Map<Property, Configuration>> extractConfig(Model model) {
109102
Map<Resource, Map<Property, Configuration>> configs = new HashMap<>();
103+
Set<Property> properties = new HashSet<>();
110104
logger.info("Extracting configuration from server response");
111105
QueryService.getConfigurations(model).forEach(entry -> {
106+
if (properties.contains(entry.property())) {
107+
throw new OntologyException(
108+
"Duplicate Property key found in Ontology: " + entry.property().toString()
109+
);
110+
}
111+
properties.add(entry.property());
112112
if (!configs.containsKey(entry.object())) {
113113
configs.put(entry.object(), new HashMap<>());
114114
}

0 commit comments

Comments
 (0)