Skip to content

Commit b5b88ba

Browse files
committed
Update v2.1.5
1 parent 9743b72 commit b5b88ba

18 files changed

+474
-433
lines changed

src/main/java/tla/backend/api/ApiController.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,27 @@
11
package tla.backend.api;
22

33
import java.io.IOException;
4+
import java.util.List;
45
import java.util.Map;
56
import java.util.stream.Collectors;
7+
import java.util.ArrayList;
68

79
import org.springframework.beans.factory.annotation.Autowired;
810
import org.springframework.boot.info.BuildProperties;
911
import org.springframework.http.HttpStatus;
12+
import org.springframework.http.MediaType;
1013
import org.springframework.http.ResponseEntity;
14+
import org.springframework.web.bind.annotation.PathVariable;
1115
import org.springframework.web.bind.annotation.RequestMapping;
1216
import org.springframework.web.bind.annotation.RequestMethod;
1317
import org.springframework.web.bind.annotation.RestController;
1418
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
1519

1620
import tla.backend.es.model.Metadata;
21+
import tla.backend.es.repo.LemmaRepo;
1722
import tla.backend.service.MetadataService;
23+
import tla.backend.api.LemmaController;
24+
1825

1926
@RestController
2027
@RequestMapping("/")
@@ -36,7 +43,7 @@ public class ApiController {
3643
public ResponseEntity<String> listEndpoints() {
3744
return new ResponseEntity<>(
3845
String.join(
39-
"\n",
46+
"<br/>",
4047
handlerMapping.getHandlerMethods().keySet().stream().flatMap(
4148
mapping -> mapping.getPatternValues().stream()
4249
).sorted().collect(
@@ -72,5 +79,4 @@ public ResponseEntity<?> getVersionInfo() throws IOException {
7279
statusCode
7380
);
7481
}
75-
7682
}

src/main/java/tla/backend/api/EntityController.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,23 @@ public ResponseEntity<SingleDocumentWrapper<? extends AbstractDto>> get(@PathVar
6161
log.error("could not find entity {}", id);
6262
throw new ObjectNotFoundException(id, this.getService().getModelClass().getSimpleName());
6363
}
64-
64+
65+
66+
/**
67+
* Returns a //TODO a single document and all documents it references.
68+
*/
69+
public Boolean existsById(String id) {
70+
Boolean result = false;
71+
result = getService().existsById(id);
72+
return result;
73+
}
74+
75+
/**
76+
* Returns the path of the service.
77+
*/
78+
public String getPath() {
79+
return this.getService().getModelPath();
80+
}
6581

6682
@CrossOrigin
6783
@RequestMapping(
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package tla.backend.api;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.web.bind.annotation.RequestMapping;
5+
import org.springframework.web.bind.annotation.RestController;
6+
7+
import tla.backend.es.model.SentenceEntity;
8+
import tla.backend.service.EntityService;
9+
import tla.backend.service.TokenService;
10+
import tla.domain.dto.SentenceDto;
11+
12+
@RestController
13+
public class TokenController extends EntityController<SentenceEntity, SentenceDto> {
14+
15+
@Autowired
16+
private TokenService service;
17+
18+
@Override
19+
public EntityService<SentenceEntity, ?, SentenceDto> getService() {
20+
return this.service;
21+
}
22+
23+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package tla.backend.api;
2+
3+
import org.springframework.beans.factory.annotation.Autowired;
4+
import org.springframework.http.HttpStatus;
5+
import org.springframework.http.MediaType;
6+
import org.springframework.http.ResponseEntity;
7+
import org.springframework.web.bind.annotation.PathVariable;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RequestMethod;
10+
import org.springframework.web.bind.annotation.RestController;
11+
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
12+
13+
14+
@RestController
15+
@RequestMapping("/typeofid")
16+
public class TypeOfIdController {
17+
18+
//Controller Beginn
19+
@Autowired
20+
private LemmaController lemmaController;
21+
22+
@Autowired
23+
private SentenceController sentenceController;
24+
25+
@Autowired
26+
private TextController textController;
27+
28+
@Autowired
29+
private CorpusObjectController corpusObjectController;
30+
31+
@Autowired
32+
private ThesaurusController thesaurusController;
33+
34+
@Autowired
35+
private TokenController tokenController;
36+
//Controller Ende
37+
38+
@Autowired
39+
private RequestMappingHandlerMapping handlerMapping;
40+
41+
/**
42+
* checks if id exists and returns index name
43+
*/
44+
@RequestMapping(
45+
value = "/{id}",
46+
method = RequestMethod.GET,
47+
consumes = MediaType.ALL_VALUE,
48+
produces = MediaType.ALL_VALUE
49+
)
50+
public ResponseEntity<String> getTypeOfId(@PathVariable String id){
51+
//TODO List of Controller aus Vererbung
52+
EntityController [] controllers = {
53+
lemmaController,
54+
sentenceController,
55+
textController,
56+
corpusObjectController,
57+
thesaurusController,
58+
tokenController
59+
};
60+
for(EntityController controller : controllers) {
61+
System.out.println(controller.existsById(id));
62+
if(controller.existsById(id)) {
63+
return new ResponseEntity<String>(
64+
controller.getPath(),
65+
HttpStatus.OK
66+
);
67+
}
68+
}
69+
return new ResponseEntity<String>(
70+
"false",
71+
HttpStatus.OK
72+
);
73+
}
74+
}

src/main/java/tla/backend/es/model/LemmaEntity.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ public class LemmaEntity extends TLAEntity {
6161
@JsonAlias({"time_span"})
6262
private TimeSpan timeSpan;
6363

64-
@Field(type = FieldType.Keyword)
65-
private Integer attestedSentencesCount;
64+
@Field(type = FieldType.Integer)
65+
private int attestedSentencesCount;
6666

6767
@Singular
6868
@Field(type = FieldType.Object)
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package tla.backend.es.model;
2+
3+
import java.util.List;
4+
5+
import org.springframework.data.elasticsearch.annotations.Document;
6+
import org.springframework.data.elasticsearch.annotations.Field;
7+
import org.springframework.data.elasticsearch.annotations.FieldType;
8+
import org.springframework.data.elasticsearch.annotations.Setting;
9+
10+
import lombok.Getter;
11+
import lombok.NoArgsConstructor;
12+
import lombok.Setter;
13+
import lombok.experimental.SuperBuilder;
14+
import tla.backend.es.model.meta.Recursable;
15+
import tla.backend.es.model.meta.UserFriendlyEntity;
16+
import tla.backend.es.model.parts.ObjectPath;
17+
import tla.backend.es.model.parts.Translations;
18+
import tla.domain.dto.TextDto;
19+
import tla.domain.model.meta.BTSeClass;
20+
import tla.domain.model.meta.TLADTO;
21+
22+
/**
23+
* Text and Subtext model
24+
*/
25+
@Getter
26+
@Setter
27+
@SuperBuilder
28+
@NoArgsConstructor
29+
@BTSeClass("BTSText")
30+
@TLADTO(TextDto.class)
31+
@Document(indexName = "text")
32+
@Setting(settingPath = "/elasticsearch/settings/indices/text.json")
33+
public class TextObjectEntity extends UserFriendlyEntity implements Recursable {
34+
35+
@Field(type = FieldType.Search_As_You_Type, name = "hash")
36+
private String SUID;
37+
38+
@Field(type = FieldType.Keyword)
39+
private String corpus;
40+
41+
@Field(type = FieldType.Object)
42+
private ObjectPath[] paths;
43+
44+
@Field(type = FieldType.Object)
45+
private List<Translations> translations;
46+
47+
@Field(type = FieldType.Object)
48+
private WordCount wordCount;
49+
50+
@Getter
51+
@Setter
52+
@NoArgsConstructor
53+
public static class WordCount {
54+
@Field(type = FieldType.Integer)
55+
int min = 0;
56+
@Field(type = FieldType.Integer)
57+
int max = 0;
58+
/**
59+
* for compatibility
60+
*/
61+
public WordCount(int count) {
62+
this.min = count;
63+
this.max = count;
64+
}
65+
}
66+
67+
}

src/main/java/tla/backend/es/model/ThsEntryEntity.java

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -60,69 +60,9 @@ public class ThsEntryEntity extends UserFriendlyEntity implements Recursable {
6060
@Field(type = FieldType.Search_As_You_Type, name = "hash")
6161
private String SUID;
6262

63-
@Field(type = FieldType.Object)
64-
private Translations translations;
65-
6663
@Field(type = FieldType.Object)
6764
private ObjectPath[] paths;
6865

69-
/**
70-
* Returns translations of a thesaurus entry's label. If no explicit translations exist, this method
71-
* attempts to extract translations from the <code>synonym_group</code> field of the passport.
72-
*/
73-
public Translations getTranslations() {
74-
if (this.translations != null) {
75-
return this.translations;
76-
} else {
77-
return this.extractTranslationsFromPassport();
78-
}
79-
}
80-
81-
/**
82-
* Convert multilingual synonyms extracted from passport to {@link Translations} object.
83-
*
84-
* @return {@link Translations} instance or <code>null</code> if no synonyms are in passport
85-
*/
86-
private Translations extractTranslationsFromPassport() {
87-
Translations res = null;
88-
if (this.getPassport() != null) {
89-
List<Passport> nodes = this.getPassport().extractProperty(
90-
SYNONYMS_PASSPORT_PATH
91-
);
92-
Map<String, List<String>> synonyms = new HashMap<>();
93-
nodes.stream().filter(
94-
n -> n.containsKey(SYNONYM_LANG_PATH) && n.containsKey(SYNONYM_VALUE_PATH)
95-
).forEach(
96-
n -> {
97-
List<String> translations = n.extractProperty(SYNONYM_VALUE_PATH).stream().map(
98-
leafNode -> leafNode.getLeafNodeValue()
99-
).collect(
100-
Collectors.toList()
101-
);
102-
n.extractProperty(SYNONYM_LANG_PATH).forEach(
103-
langValueNode -> {
104-
String lang = langValueNode.getLeafNodeValue();
105-
if (synonyms.containsKey(lang)) {
106-
synonyms.get(lang).addAll(translations);
107-
} else {
108-
synonyms.put(lang, new ArrayList<String>(translations));
109-
}
110-
}
111-
);
112-
}
113-
);
114-
try {
115-
res = objectMapper.readValue(
116-
objectMapper.writeValueAsString(synonyms),
117-
Translations.class
118-
);
119-
} catch (Exception e) {
120-
log.error("something went wrong during synonum extraction", e);
121-
}
122-
}
123-
return res;
124-
}
125-
12666
/**
12767
* Returns the timespan represented by a thesaurus entry in the form of a list
12868
* of size 2 containing first and last year.

src/main/java/tla/backend/es/model/meta/ModelConfig.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,7 @@ protected static ModelMapper initModelMapper() {
256256
LemmaEntity::getRevisionState, LemmaDto::setReviewState
257257
);
258258
modelMapper.createTypeMap(ThsEntryEntity.class, ThsEntryDto.class)
259-
.addMappings(
260-
m -> m.using(translationsToMapConverter).map(
261-
ThsEntryEntity::getTranslations, ThsEntryDto::setTranslations
262-
)
263-
).addMapping(
259+
.addMapping(
264260
ThsEntryEntity::getRevisionState, ThsEntryDto::setReviewState
265261
);
266262
modelMapper.createTypeMap(TextEntity.class, TextDto.class)

src/main/java/tla/backend/es/query/ESQueryBuilder.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import static org.elasticsearch.index.query.QueryBuilders.idsQuery;
55
import static org.elasticsearch.index.query.QueryBuilders.matchQuery;
66

7+
import java.util.HashMap;
78
import java.util.LinkedList;
89
import java.util.List;
10+
import java.util.Map;
911

1012
import org.elasticsearch.index.query.BoolQueryBuilder;
1113
import org.elasticsearch.search.aggregations.AbstractAggregationBuilder;
@@ -42,7 +44,22 @@ public ESQueryBuilder() {
4244
this.nativeAggregationBuilders = new LinkedList<>();
4345
this.dependencies = new LinkedList<>();
4446
}
45-
47+
static final Map<String, String> criterias;
48+
static { criterias = new HashMap<String, String>();
49+
criterias.put("timeSpan.begin_asc", "timeSpan.end_asc");
50+
criterias.put("timeSpan.begin_desc","timeSpan.end_desc");
51+
criterias.put("timeSpan.end_asc", "timeSpan.begin_asc");
52+
criterias.put("timeSpan.end_desc", "timeSpan.begin_desc");
53+
//TODO Sortierkriterien vom Frontend mappen und nicht direkt auf ES zugreifen lassen
54+
//TODO Mapping for other criterias sortKey,attestedSentenceCounts
55+
};
56+
57+
public void setTimeSpanCriterias(String criteria) {
58+
if(criterias.containsKey(criteria)) {
59+
this.sortSpec.addSortingByString(criterias.get(criteria));
60+
}
61+
}
62+
4663
/**
4764
* Put together an actual Elasticsearch query ready for execution.
4865
*/

0 commit comments

Comments
 (0)