Commit c3af6ac7 authored by Matija Obreza's avatar Matija Obreza
Browse files

Loggers layout and using PageImpl

parent de55d192
...@@ -13,6 +13,8 @@ import org.apache.log4j.LogManager; ...@@ -13,6 +13,8 @@ import org.apache.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.genesys2.server.servlet.controller.AdminController; import org.genesys2.server.servlet.controller.AdminController;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
...@@ -26,100 +28,98 @@ import org.springframework.web.bind.annotation.RequestParam; ...@@ -26,100 +28,98 @@ import org.springframework.web.bind.annotation.RequestParam;
@PreAuthorize("hasRole('ADMINISTRATOR')") @PreAuthorize("hasRole('ADMINISTRATOR')")
public class LoggerController { public class LoggerController {
public static final Log LOG = LogFactory.getLog(AdminController.class); public static final Log LOG = LogFactory.getLog(AdminController.class);
@Value("${list.logger.pagination.size}") @Value("${paginator.default.pageSize}")
int size; int defaultPageSize;
private Logger logger; @RequestMapping(method = RequestMethod.GET, value = "/adjustLogger")
public String adjustLogger(Model model, @RequestParam(value = "page", defaultValue = "1") int page) {
@RequestMapping(method = RequestMethod.GET, value = "/adjustLogger") // first element on page
public String adjustLogger(Model model, @RequestParam(value = "page", defaultValue = "1") Integer page){ int firstelement = (page - 1) * defaultPageSize;
int size = this.size;
List<Logger> allLoggers = getAllLoggers();
//first element on page List<Logger> loggers = new ArrayList<>();
int firstelement = (page==null)?0:(page-1) * size;
// copy part of array
List<Logger> allLoggers = getAllLoggers(); for (int i = 0; i < defaultPageSize && i < allLoggers.size(); i++) {
int totalPage = allLoggers.size()/size + 1; loggers.add(allLoggers.get(firstelement + i));
}
List<Logger> loggers = new ArrayList<>();
PageImpl<Logger> pagedData = new PageImpl<Logger>(loggers, new PageRequest(page, defaultPageSize), allLoggers.size());
if(size > (allLoggers.size() - firstelement)){ model.addAttribute("loggers", pagedData);
size = allLoggers.size() - firstelement; return "/admin/adjust-logger/loggersList";
} }
//copy part of array @RequestMapping(method = RequestMethod.GET, value = "/adjustLoggerPage/{loggerName}")
for(int i = 0; i<size; i++){ public String adjustLoggerPage(Model model, @PathVariable(value = "loggerName") String loggerName) {
loggers.add(allLoggers.get(firstelement+i)); Logger logger;
}
if (loggerName != null && "root".equalsIgnoreCase(loggerName))
model.addAttribute("loggers", loggers); logger = LogManager.getRootLogger();
model.addAttribute("pageNumber", page); else
model.addAttribute("totalPage", totalPage); logger = LogManager.getLogger(loggerName);
return "/admin/adjust-logger/loggersList";
} model.addAttribute("logger", logger);
model.addAttribute("appenders", logger.getRootLogger().getAllAppenders());
@RequestMapping(method = RequestMethod.GET, value = "/adjustLoggerPage/{loggerName}") return "/admin/adjust-logger/adjustLoggerPage";
public String adjustLoggerPage(Model model, @PathVariable(value = "loggerName")String loggerName){ }
if (loggerName != null && "root".equalsIgnoreCase(loggerName))
logger = LogManager.getRootLogger(); @RequestMapping(method = RequestMethod.POST, value = "/changeLoger")
else public String changeLogger(@RequestParam(value = "loggerLevel") String loggerLevel, @RequestParam(value = "loggerName") String loggerName) {
logger = LogManager.getLogger(loggerName); Logger logger;
model.addAttribute("logger", logger);
model.addAttribute("appenders", logger.getRootLogger().getAllAppenders()); if (loggerName == null || "root".equalsIgnoreCase(loggerName)) {
return "/admin/adjust-logger/adjustLoggerPage"; logger = LogManager.getRootLogger();
} } else {
logger = LogManager.getLogger(loggerName);
@RequestMapping(method = RequestMethod.POST, value = "/changeLoger") }
public String changeLogger(@RequestParam(value = "loggerLevel") String loggerLevel,
@RequestParam(value = "loggerName") String loggerName){ if (logger != null) {
if (loggerName != null && "root".equalsIgnoreCase(loggerName)) LOG.debug("Got logger: " + logger.getName());
logger = LogManager.getRootLogger(); logger.setLevel(loggerLevel == null ? null : Level.toLevel(loggerLevel));
else }
logger = LogManager.getLogger(loggerName);
if (logger != null) { return "redirect:/admin/logger/adjustLoggerPage/" + loggerName + ".";
LOG.debug("Got logger: " + logger.getName()); }
logger.setLevel(loggerLevel == null ? null : Level.toLevel(loggerLevel));
} private List<Logger> getAllLoggers() {
return "redirect:/logger/adjustLoggerPage/" + loggerName+".";
} Enumeration<Logger> en = LogManager.getCurrentLoggers();
List<Logger> loggers = new ArrayList<>();
private List<Logger> getAllLoggers(){
while (en.hasMoreElements()) {
Enumeration<Logger> en = LogManager.getCurrentLoggers(); Logger logger = en.nextElement();
List<Logger> loggers = new ArrayList<>(); if (logger.getLevel() != null)
loggers.add(logger);
while (en.hasMoreElements()) { }
loggers.add(en.nextElement());
} loggers.add(LogManager.getRootLogger());
loggers.add(LogManager.getRootLogger()); Collections.sort(loggers, new Comparator<Logger>() {
@Override
Collections.sort(loggers, new Comparator<Logger>() { public int compare(Logger o1, Logger o2) {
@Override // root logger is on the top
public int compare(Logger o1, Logger o2) { if (LogManager.getRootLogger() == o1) {
// root logger is on the top return -1;
if (LogManager.getRootLogger() == o1) { }
return -1; if (LogManager.getRootLogger() == o2) {
} return 1;
if (LogManager.getRootLogger() == o2) { }
return 1; // otherwise sort by name
} return o1.getName().compareTo(o2.getName());
// otherwise sort by name }
return o1.getName().compareTo(o2.getName()); });
}
}); return loggers;
}
return loggers;
} @RequestMapping(method = RequestMethod.POST, value = "/addLoger")
public String addLogger(@RequestParam(value = "nameNewLogger") String nameNewLogger, Model model) {
@RequestMapping(method = RequestMethod.POST, value = "/addLoger") Logger logger = Logger.getLogger(nameNewLogger);
public String addLogger(@RequestParam(value = "nameNewLogger") String nameNewLogger, Model model){ logger.setLevel(Level.INFO);
Logger.getLogger(nameNewLogger);
return "redirect:/admin/adjustLogger"; return "redirect:/admin/logger/adjustLogger";
} }
} }
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
#------------------------------------------------------------------------------- #-------------------------------------------------------------------------------
#Paginator #Paginator
paginator.default.pageSize=2 paginator.default.pageSize=50
paginator.default.fastStep=3 paginator.default.fastStep=3
paginator.default.maxPage=4 paginator.default.maxPage=4
......
...@@ -392,8 +392,6 @@ metadata.page.title=Datasets ...@@ -392,8 +392,6 @@ metadata.page.title=Datasets
metadata.page.view.title=Dataset details metadata.page.view.title=Dataset details
metadata.download-dwca=Download ZIP metadata.download-dwca=Download ZIP
page.login=Login page.login=Login
adjust.loggers.list.page=List of loggers
adjust.logger.edit.page=Adjust logger configuration page
traits.page.title=Descriptors traits.page.title=Descriptors
trait-list=Descriptors trait-list=Descriptors
...@@ -410,8 +408,6 @@ menu.report-an-issue=Report an issue ...@@ -410,8 +408,6 @@ menu.report-an-issue=Report an issue
menu.scm=Source code menu.scm=Source code
menu.translate=Translate Genesys menu.translate=Translate Genesys
logger.name=Logger name
article.edit-article=Editing article article.edit-article=Editing article
article.slug=Article slug (URL) article.slug=Article slug (URL)
article.title=Article title article.title=Article title
...@@ -582,3 +578,11 @@ cache.stat.map.ownedEntryCount=Owned cache entries ...@@ -582,3 +578,11 @@ cache.stat.map.ownedEntryCount=Owned cache entries
cache.stat.map.lockedEntryCount=Locked cache entries cache.stat.map.lockedEntryCount=Locked cache entries
cache.stat.map.puts=Number of writes to cache cache.stat.map.puts=Number of writes to cache
cache.stat.map.hits=Number of cache hits cache.stat.map.hits=Number of cache hits
loggers.list.page=List of configured loggers
logger.add-logger=Add logger
logger.edit.page=Logger configuration page
logger.name=Logger name
logger.log-level=Log level
logger.appenders=Log appenders
...@@ -5,60 +5,55 @@ ...@@ -5,60 +5,55 @@
<html> <html>
<head> <head>
<title><spring:message code="adjust.logger.edit.page"/></title> <title><spring:message code="logger.edit.page"/></title>
</head> </head>
<body> <body>
<h1><spring:message code="adjust.logger.edit.page"/></h1> <h1><spring:message code="logger.edit.page"/></h1>
<div class="logger-detail"> <div class="row">
<div class="logger-name"> <div class="col-sm-4"><label><spring:message code="logger.name" /></label></div>
<div>Loger name - ${logger.name}</div> <div class="col-sm-8"><p class=".form-control-static">${logger.name}</p></div>
</div> </div>
<div class="logger-level"> <div class="row">
<div>Loger level - ${logger.level}</div> <div class="col-sm-4"><label><spring:message code="logger.log-level" /><label></div>
<div class="col-sm-8 control-label"><p class=".form-control-static">${logger.level}</p></div>
</div> </div>
<div class="all-appenders">
Appenders: <ul class="funny-list">
<ul>
<c:forEach items="${appenders}" var="appender"> <c:forEach items="${appenders}" var="appender">
<li> <li>
${appender.name} <c:out value="${appender.name}" />
</li> </li>
</c:forEach> </c:forEach>
</ul> </ul>
</div>
<div>
<div class="change-level-label">Change level</div>
<form method="post" class="form-change-level form-inline" action=<c:url value="/admin/logger/changeLoger"/> >
<form method="post" class="form-horizontal" action=<c:url value="/admin/logger/changeLoger"/> >
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<input type="hidden" name="loggerName" value="${logger.name}"/> <input type="hidden" name="loggerName" value="${logger.name}"/>
<div class="form-group"> <div class="form-group">
<label class="col-sm-4 control-label"><spring:message code="logger.log-level" /></label>
<div class="col-sm-8">
<select class="form-control" name="loggerLevel"> <select class="form-control" name="loggerLevel">
<c:forTokens items="all,debug,info,warn,error,fatal,off,trace" delims="," var="level"> <c:forTokens items="all,debug,info,warn,error,fatal,off,trace" delims="," var="level">
<option value="${level}"> <option value="${level}" ${level == logger.level.toString().toLowerCase() ? "selected" : ""}>
${level} ${level}
</option> </option>
</c:forTokens> </c:forTokens>
</select> </select>
</div>
</div> </div>
<!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<div class="form-group"> <div class="form-group">
<input type="submit" class="btn btn-group-sm"> <div class="col-sm-offset-4 col-sm-8">
<input type="submit" class="btn btn-group-sm" value="<spring:message code="save" />">
<a class="btn btn-default" href="<c:url value="/admin/logger/adjustLogger" />"><spring:message code="cancel" /></a>
</div> </div>
<div class="form-group">
<a class="btn btn-default" href="<c:url value="/admin/logger/adjustLogger" />">Cancel</a>
</div> </div>
</form> </form>
</div>
</div> </div>
</body> </body>
</html> </html>
...@@ -5,54 +5,43 @@ ...@@ -5,54 +5,43 @@
<html> <html>
<head> <head>
<title><spring:message code="adjust.loggers.list.page"/></title> <title><spring:message code="loggers.list.page"/></title>
</head> </head>
<body> <body>
<h1><spring:message code="adjust.loggers.list.page"/></h1> <h1><spring:message code="loggers.list.page"/></h1>
<div class="main-col-header clearfix"> <div class="main-col-header clearfix">
<div class="nav-header pull-left"> <div class="nav-header pull-left">
<div class="results"><spring:message code="paged.totalElements" arguments="${totalPage}" /></div> <div class="results"><spring:message code="paged.totalElements" arguments="${loggers.totalElements}" /></div>
<div class="pagination"> <div class="pagination">
<spring:message code="paged.pageOfPages" arguments="${pageNumber},${totalPage}" /> <spring:message code="paged.pageOfPages" arguments="${loggers.number},${loggers.totalPages}" />
<a class="${pageNumber-1 eq 0 ? 'disabled' :''}" href="?page=${pageNumber-1 eq 0 ? 1 : pageNumber-1}"><spring:message code="pagination.previous-page" /></a> <a href="?page=${pageNumber + 1}"><spring:message code="pagination.next-page" /></a> <a class="${pageNumber-1 eq 0 ? 'disabled' :''}" href="?page=${loggers.number-1 eq 0 ? 1 : loggers.number-1}"><spring:message code="pagination.previous-page" /></a> <a href="?page=${loggers.number + 1}"><spring:message code="pagination.next-page" /></a>
</div> </div>
</div> </div>
</div> </div>
<div> <div class="row">
<form method="post" action=<c:url value="/admin/logger/addLoger"/> >
<div class="change-level-label">Add logger</div> <div class="form-group col-sm-10">
<form method="post" class="form-change-level form-inline" action=<c:url value="/admin/logger/addLoger"/> >
<div class="form-group col-sm-3">
<input class="form-control" type="text" name="nameNewLogger" placeholder="com.example.package.Class"/> <input class="form-control" type="text" name="nameNewLogger" placeholder="com.example.package.Class"/>
</div> </div>
<!-- CSRF protection --> <!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
<div class="form-group col-sm-2">
<div class="form-group col-sm-3"> <input type="submit" class="btn" value="<spring:message code="logger.add-logger" />" />
<input type="submit" class="btn btn-group-sm">
</div> </div>
</form> </form>
</div> </div>
<table class="all-loggers"> <ul class="funny-list">
<thead> <c:forEach items="${loggers.content}" var="logger" varStatus="status">
<tr> <li class="${status.count % 2 == 0 ? 'even' : 'odd'}">
<td><spring:message code="logger.name" /></td> <a class="adjust-logger-config" href="<c:url value="/admin/logger/adjustLoggerPage/${logger.name}." />">${logger.name}</a>
</tr> <div class="pull-right"><c:out value="${logger.level}" /></div>
</thead> </li>
<tbody>
<c:forEach items="${loggers}" var="logger" varStatus="status">
<tr class="${status.count % 2 == 0 ? 'even' : 'odd'} particular-logger">
<td><a class="adjust-logger-config" href="<c:url value="/admin/logger/adjustLoggerPage/${logger.name}." />">${logger.name}</a></td>
</tr>
</c:forEach> </c:forEach>
</tbody> </ul>
</table>
</body> </body>
</html> </html>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment