Fixed the order of annotation keys and values, and added tests.
Change-Id: I1e6a9f27cea2f395bb7c5f27967e5a2d891420ba
diff --git a/full/src/main/java/de/ids_mannheim/korap/annotation/AnnotationParser.java b/full/src/main/java/de/ids_mannheim/korap/annotation/AnnotationParser.java
index ab3cd02..c05ae6b 100644
--- a/full/src/main/java/de/ids_mannheim/korap/annotation/AnnotationParser.java
+++ b/full/src/main/java/de/ids_mannheim/korap/annotation/AnnotationParser.java
@@ -141,18 +141,19 @@
if (layer == null) {
computeLayer(annotationCode);
}
- String code = array.get(1);
- if (code.endsWith("=") || code.endsWith(":")) {
- code = code.substring(0, code.length() - 1);
- }
+
Annotation annotation = null;
if (array.size() == 2) {
+ String code = array.get(1);
+ if (code.endsWith("=") || code.endsWith(":")) {
+ code = code.substring(0, code.length() - 1);
+ }
annotation = retrieveOrCreateAnnotation(code, annotationType,
null, array.get(0));
}
else if (array.size() == 3) {
- annotation = retrieveOrCreateAnnotation(code, annotationType,
- array.get(1), array.get(2));
+ annotation = retrieveOrCreateAnnotation(array.get(0),
+ annotationType, array.get(1), array.get(2));
}
if (annotation != null) {
AnnotationKey annotationKey =
@@ -167,8 +168,7 @@
if (this.key == null) {
computeKey(annotationCode);
}
- String valueCode = array.get(0);
- Annotation value = retrieveOrCreateAnnotation(valueCode,
+ Annotation value = retrieveOrCreateAnnotation(array.get(0),
AnnotationType.VALUE, array.get(1), array.get(2));
if (value != null) {
values.add(value);
diff --git a/full/src/main/java/de/ids_mannheim/korap/config/Initializator.java b/full/src/main/java/de/ids_mannheim/korap/config/Initializator.java
index 1cccb4f..e6347e8 100644
--- a/full/src/main/java/de/ids_mannheim/korap/config/Initializator.java
+++ b/full/src/main/java/de/ids_mannheim/korap/config/Initializator.java
@@ -45,8 +45,10 @@
resourceParser.run();
}
- public void initTest () {
+ public void initTest () throws IOException, KustvaktException {
setInitialAccessScope();
+ annotationParser.run();
+ resourceParser.run();
}
private void setInitialAccessScope () {
diff --git a/full/src/main/java/de/ids_mannheim/korap/dto/FoundryDto.java b/full/src/main/java/de/ids_mannheim/korap/dto/FoundryDto.java
index aa6ef2f..26cf383 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dto/FoundryDto.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dto/FoundryDto.java
@@ -2,6 +2,7 @@
import java.util.List;
import java.util.Map;
+import java.util.Set;
import org.codehaus.jackson.map.annotate.JsonSerialize;
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
@@ -36,14 +37,14 @@
public class Layer {
private String code;
private String description;
- private List<Key> keys;
+ private Set<Key> keys;
}
@Getter
@Setter
@JsonInclude(Include.NON_EMPTY)
@JsonSerialize(include=Inclusion.NON_EMPTY) // old codehouse annotation used by jersey
- public class Key {
+ public class Key implements Comparable<Key>{
private String code;
private String description;
@@ -52,5 +53,10 @@
public Key (String code) {
this.code = code;
}
+
+ @Override
+ public int compareTo (Key k) {
+ return this.code.compareTo(k.code);
+ }
}
}
diff --git a/full/src/main/java/de/ids_mannheim/korap/dto/converter/AnnotationConverter.java b/full/src/main/java/de/ids_mannheim/korap/dto/converter/AnnotationConverter.java
index 272d4c8..efe1c43 100644
--- a/full/src/main/java/de/ids_mannheim/korap/dto/converter/AnnotationConverter.java
+++ b/full/src/main/java/de/ids_mannheim/korap/dto/converter/AnnotationConverter.java
@@ -4,6 +4,9 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
import org.springframework.stereotype.Component;
@@ -86,11 +89,12 @@
}
Annotation layer = f.getLayer();
- List<Key> keys = new ArrayList<>();
+ Set<Key> keys = new TreeSet<>();
for (AnnotationKey ak : f.getKeys()) {
Annotation a = ak.getKey();
- Map<String, String> values = new HashMap<>();
+ Map<String, String> values = new TreeMap<>();
+
Key key = dto.new Key(a.getCode());
if (language.equals("de")) {
key.setDescription(a.getGermanDescription());
diff --git a/full/src/main/java/de/ids_mannheim/korap/entity/Annotation.java b/full/src/main/java/de/ids_mannheim/korap/entity/Annotation.java
index f644b25..35ee11d 100644
--- a/full/src/main/java/de/ids_mannheim/korap/entity/Annotation.java
+++ b/full/src/main/java/de/ids_mannheim/korap/entity/Annotation.java
@@ -23,15 +23,6 @@
@Table(name = "annotation")
public class Annotation {
- public Annotation () {}
-
- public Annotation (String code, String type, String text, String description) {
- this.code = code;
- this.type = type;
- this.text = text;
- this.description = description;
- }
-
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
@@ -42,6 +33,16 @@
@Column(name = "de_description")
private String germanDescription;
+ public Annotation () {}
+
+ public Annotation (String code, String type, String text,
+ String description) {
+ this.code = code;
+ this.type = type;
+ this.text = text;
+ this.description = description;
+ }
+
@Override
public String toString () {
return "id=" + id + ", code= " + code + ", type= " + type