-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathJournalController.java
88 lines (81 loc) · 3.91 KB
/
JournalController.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
* Made with all the love in the world
* by scireum in Remshalden, Germany
*
* Copyright by scireum GmbH
* http://www.scireum.de - [email protected]
*/
package sirius.biz.protocol;
import sirius.biz.web.BizController;
import sirius.biz.web.ElasticPageHelper;
import sirius.db.mixing.DateRange;
import sirius.db.mixing.query.QueryField;
import sirius.kernel.di.std.Register;
import sirius.web.controller.DefaultRoute;
import sirius.web.controller.Routed;
import sirius.web.http.WebContext;
import sirius.web.security.Permission;
/**
* Provides a GUI for viewing the system journal recorded by {@link JournalData} / {@link JournalEntry}.
*/
@Register(framework = Protocols.FRAMEWORK_JOURNAL)
public class JournalController extends BizController {
/**
* Displays all changes on entries recorded by the protocol.
*
* @param webContext the current request
*/
@Permission(Protocols.PERMISSION_SYSTEM_JOURNAL)
@DefaultRoute
@Routed("/system/protocol")
public void protocol(WebContext webContext) {
ElasticPageHelper<JournalEntry> pageHelper =
ElasticPageHelper.withQuery(elastic.select(JournalEntry.class).orderDesc(JournalEntry.TOD));
pageHelper.withContext(webContext);
pageHelper.addTermAggregation(JournalEntry.TARGET_TYPE);
pageHelper.addTimeAggregation(JournalEntry.TOD,
false,
DateRange.LAST_FIVE_MINUTES,
DateRange.LAST_FIFTEEN_MINUTES,
DateRange.LAST_TWO_HOURS,
DateRange.TODAY,
DateRange.YESTERDAY,
DateRange.THIS_WEEK,
DateRange.LAST_WEEK);
pageHelper.withSearchFields(QueryField.contains(JournalEntry.SEARCH_FIELD));
pageHelper.withTotalCount();
webContext.respondWith().template("/templates/biz/protocol/protocol.html.pasta", pageHelper.asPage());
}
/**
* Displays all changes on entries recorded for a given entity by the protocol.
*
* @param webContext the current request
* @param type the type of the object to report the journal for
* @param id the id of the object to report the journal for
*/
@Routed("/system/protocol/:1/:2")
public void entityProtocol(WebContext webContext, String type, String id) {
if (!verifySignedLink(webContext)) {
return;
}
ElasticPageHelper<JournalEntry> pageHelper = ElasticPageHelper.withQuery(elastic.select(JournalEntry.class)
.eq(JournalEntry.TARGET_TYPE,
type)
.eq(JournalEntry.TARGET_ID, id)
.orderDesc(JournalEntry.TOD));
pageHelper.withContext(webContext)
.addTimeAggregation(JournalEntry.TOD,
false,
DateRange.LAST_FIVE_MINUTES,
DateRange.LAST_FIFTEEN_MINUTES,
DateRange.LAST_TWO_HOURS,
DateRange.TODAY,
DateRange.YESTERDAY,
DateRange.THIS_WEEK,
DateRange.LAST_WEEK)
.withSearchFields(QueryField.contains(JournalEntry.SEARCH_FIELD))
.withTotalCount();
webContext.respondWith()
.template("/templates/biz/protocol/entity_protocol.html.pasta", type, id, pageHelper.asPage());
}
}