-
Notifications
You must be signed in to change notification settings - Fork 3
/
AnalyzerController.java
71 lines (60 loc) · 2.28 KB
/
AnalyzerController.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package by.pbortnik.analyzer.controller;
import by.pbortnik.analyzer.model.AnalyzedItemRs;
import by.pbortnik.analyzer.model.CleanIndexRq;
import by.pbortnik.analyzer.model.IndexLaunch;
import by.pbortnik.analyzer.model.IndexRs;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
@Controller
public class AnalyzerController {
@Autowired
private SimpleStorage simpleStorage;
@RequestMapping(value = "/_analyze", method = RequestMethod.POST, consumes = APPLICATION_JSON)
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public List<AnalyzedItemRs> analyze(@RequestBody List<IndexLaunch> launches) {
List<AnalyzedItemRs> response = new ArrayList<>();
IndexLaunch indexLaunch = launches.get(0);
indexLaunch.getTestItems().forEach(item -> {
if (item.getLogs().stream().anyMatch(it -> it.getMessage().contains("AssertionError"))) {
item.setIssueType("PB001");
}
simpleStorage.getRepository()
.entrySet()
.stream()
.flatMap(it -> it.getValue().stream())
.flatMap(it -> it.getTestItems().stream())
.filter(it -> it.getUniqueId().equals(item.getUniqueId()))
.findFirst()
.ifPresent(it -> {
AnalyzedItemRs analyzedItem = new AnalyzedItemRs();
analyzedItem.setItemId(item.getTestItemId());
analyzedItem.setIssueType(it.getIssueType());
response.add(analyzedItem);
});
});
return response;
}
@RequestMapping(value = "/_index", method = RequestMethod.POST, consumes = APPLICATION_JSON)
@ResponseBody
@ResponseStatus(HttpStatus.OK)
public IndexRs index(@RequestBody List<IndexLaunch> launches) {
simpleStorage.addAll(launches);
return null;
}
@RequestMapping(value = "/_index/{project}", method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.OK)
public void deleteIndex(@PathVariable String project) {
simpleStorage.removeProject(project);
}
@RequestMapping(value = "/_index/delete", method = RequestMethod.PUT)
@ResponseStatus(HttpStatus.OK)
public void cleanIndex(@RequestBody CleanIndexRq rq) {
simpleStorage.cleanIndex(rq.getIds(), rq.getProject());
}
}