19 package org.turro.log;
21 import java.util.List;
22 import java.util.Optional;
23 import org.turro.string.Strings;
24 import org.turro.elephant.db.ElephantPU;
25 import org.turro.elephant.db.WhereClause;
26 import org.turro.elephant.entities.db.SystemLog;
27 import org.turro.elephant.util.DateFormats;
28 import org.turro.entities.Entities;
29 import org.turro.entities.IElephantEntity;
30 import org.turro.i18n.I_;
31 import org.turro.jpa.serializer.SerializerMessage;
32 import org.turro.zkoss.grid.PagingGrid;
33 import org.zkoss.zk.ui.Component;
34 import org.zkoss.zk.ui.event.Event;
35 import org.zkoss.zk.ui.event.EventListener;
36 import org.zkoss.zk.ui.event.Events;
37 import org.zkoss.zk.ui.ext.AfterCompose;
38 import org.zkoss.zul.Column;
39 import org.zkoss.zul.Columns;
40 import org.zkoss.zul.Image;
41 import org.zkoss.zul.Label;
42 import org.zkoss.zul.Row;
43 import org.zkoss.zul.Rows;
44 import org.zkoss.zul.Space;
52 private String comment, generatorPath, entityPath;
56 this.comment = comment;
60 this.generatorPath = generatorPath;
64 this.entityPath = entityPath;
75 private void populateRows() {
80 List<SystemLog> entries = getEntries();
83 row.appendChild(
new Label(
I_.
byKey(entry.getLogType().toString()) +
84 (entry.getCounts() > 1 ?
"(" + entry.getCounts()+
")" :
"")));
86 if(Strings.isBlank(generatorPath)) {
89 if(obj instanceof Component) {
90 row.appendChild((Component) obj);
92 row.appendChild(
new Label(entry.getGeneratorName()));
95 if(Strings.isBlank(entityPath)) {
96 IElephantEntity iee = Entities.
getController(entry.getEntityPath());
98 if(obj instanceof Component) {
99 row.appendChild((Component) obj);
100 if(obj instanceof AfterCompose) {
101 ((AfterCompose) obj).afterCompose();
104 row.appendChild(
new Label(Strings.isBlank(entry.getEntityName(), iee.getLabel())));
107 row.appendChild(
new Label(entry.getComment()));
108 final Object data = Optional.ofNullable(entry.getObject()).orElse(entry.getString());
109 if(!(data instanceof String)) {
110 row.appendChild(
new Space());
111 }
else if(isReadableAndShort((String) data)) {
112 row.appendChild(
new Label((String) data));
114 Image info =
new Image(
"/_zul/images/info.png");
115 info.addEventListener(Events.ON_CLICK,
new EventListener<Event>() {
117 public void onEvent(Event event) throws Exception {
118 new SerializerMessage((String) data).show(getPage());
121 row.appendChild(info);
123 rows.appendChild(row);
128 private List<SystemLog> getEntries() {
129 WhereClause wc =
new WhereClause();
130 wc.addClause(
"select l from SystemLog as l");
131 if(!
"*".equals(comment)) {
132 wc.setPrefix(
"where");
133 wc.addLikeFields(
new String[] {
"l.comment"}, comment);
135 wc.addClause(
"where 1=1");
138 if(!Strings.isBlank(generatorPath)) {
139 wc.addClause(
"and l.generatorPath = :generatorPath");
140 wc.addNamedValue(
"generatorPath", generatorPath);
142 if(!Strings.isBlank(entityPath)) {
143 wc.addClause(
"and l.entityPath = :entityPath");
144 wc.addNamedValue(
"entityPath", entityPath);
146 wc.addClause(
"order by l.dateLog desc");
147 return new ElephantPU().getResultList(wc, max);
150 private void addColumns() {
151 Columns cols = getColumns(
true);
152 cols.appendChild(
new Column(I_.get(
"Type"),
null,
"80px"));
153 cols.appendChild(
new Column(I_.get(
"Date"),
null,
"150px"));
154 if(Strings.isBlank(generatorPath)) {
155 cols.appendChild(
new Column(I_.get(
"Generator"),
null,
"20%"));
157 if(Strings.isBlank(entityPath)) {
158 cols.appendChild(
new Column(I_.get(
"Entity"),
null,
"30%"));
160 cols.appendChild(
new Column(I_.get(
"Comment"),
null,
"20%"));
161 cols.appendChild(
new Column(I_.get(
"Data"),
null,
"20%"));
164 private boolean isReadableAndShort(String data) {
165 return (!(data.startsWith(
"<") || data.startsWith(
"{")) && data.length() <= 50);
static IElephantEntity getController(String path)
static String byKey(String key)
void setGeneratorPath(String generatorPath)
void setComment(String comment)
void setEntityPath(String entityPath)
Rows getRows(boolean create)
void setRowCount(int rows)
IElephantEntity getController(String entityPath)