
org.glassfish.admingui.common.handlers.LogViewHandlers Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of console-common Show documentation
Show all versions of console-common Show documentation
This bundle contains common code that may be shared across plugins.
The newest version!
/*
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package org.glassfish.admingui.common.handlers;
import com.sun.jsftemplating.annotation.Handler;
import com.sun.jsftemplating.annotation.HandlerInput;
import com.sun.jsftemplating.annotation.HandlerOutput;
import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext;
import com.sun.jsftemplating.util.Util;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Level;
import org.glassfish.admingui.common.util.GuiUtil;
public class LogViewHandlers {
/**
* Creates a new instance of LogViewHandlers
*/
public LogViewHandlers() {
}
/**
* This handler creates a Map<String, String> which contains the
* QUERY_STRING parameters that should be passed to the REST logging
* endpoint to make a query with the given constraints.
*
* @param context The HandlerContext.
*/
@Handler(id = "gf.getLogQueryAttributes",
input = {
@HandlerInput(name = "InstanceName", type = String.class, required = true),
@HandlerInput(name = "LogFileName", type = String.class, required = true),
@HandlerInput(name = "LogLevel", type = String.class, required = true),
@HandlerInput(name = "FromRecord", type = Integer.class),
@HandlerInput(name = "AfterRecord", type = Boolean.class),
@HandlerInput(name = "DateEnabled", type = String.class),
@HandlerInput(name = "FromDate", type = Object.class),
@HandlerInput(name = "FromTime", type = Object.class),
@HandlerInput(name = "ToDate", type = Object.class),
@HandlerInput(name = "ToTime", type = Object.class),
@HandlerInput(name = "Loggers", type = Object.class),
@HandlerInput(name = "CustomLoggers", type = Object.class),
@HandlerInput(name = "anySearch", type = String.class),
@HandlerInput(name = "NumToDisplay", type = Integer.class),
@HandlerInput(name = "OnlyLevel", type = Boolean.class, defaultValue = "false"),
@HandlerInput(name = "LogDateSortDirection", type = Boolean.class)},
output = {
@HandlerOutput(name = "attributes", type = Map.class)})
public static void getLogQueryAttributes(HandlerContext handlerCtx) {
// Create a Map to hold the attributes
Map attMap = new HashMap();
// Attempt to read values passed in
String logFileName = (String) handlerCtx.getInputValue("LogFileName");
Integer fromRecord = (Integer) handlerCtx.getInputValue("FromRecord");
Boolean after = (Boolean) handlerCtx.getInputValue("AfterRecord");
String dateEnabledString = (String) handlerCtx.getInputValue("DateEnabled");
Object fromDate = handlerCtx.getInputValue("FromDate");
Object fromTime = handlerCtx.getInputValue("FromTime");
Object toDate = handlerCtx.getInputValue("ToDate");
Object toTime = handlerCtx.getInputValue("ToTime");
Object loggers = handlerCtx.getInputValue("Loggers");
String logLevel = (String) handlerCtx.getInputValue("LogLevel");
Object customLoggers = handlerCtx.getInputValue("CustomLoggers");
String anySearch = (String) handlerCtx.getInputValue("anySearch");
Integer numberToDisplay = (Integer) handlerCtx.getInputValue("NumToDisplay");
Boolean onlyLevel = (Boolean) handlerCtx.getInputValue("OnlyLevel");
Boolean direction = (Boolean) handlerCtx.getInputValue("LogDateSortDirection");
String instanceName = (String) handlerCtx.getInputValue("InstanceName");
notNullStringPut(attMap, "instanceName", instanceName);
if ((instanceName != null)) {
if (logFileName != null) {
Date from;
Date to;
// Convert Date/Time fields
if ((dateEnabledString != null)
&& ("enabled".equalsIgnoreCase(dateEnabledString)
|| "true".equalsIgnoreCase(dateEnabledString))) {
// Date is enabled, figure out what the values are
from = convertDateTime(handlerCtx, fromDate, fromTime);
to = convertDateTime(handlerCtx, toDate, toTime);
if ((from == null)) {
GuiUtil.handleError(handlerCtx, "Specific Date Range was chosen, however, date fields are incomplete.");
}
if (to != null && from != null) {
if (from.after(to)) {
GuiUtil.handleError(handlerCtx, "Timestamp value of 'From: ' field " + fromDate
+ " must not be greater than 'To: ' field value " + toDate);
}
}
} else {
// Date not enabled, ignore from/to dates
from = null;
to = null;
}
if ((logLevel != null) && (logLevel.trim().length() == 0)) {
logLevel = null;
}
// Convert module array to List
//List moduleList = null;
//Set moduleList = new HashSet();
String listOfModules = "";
String sep = "";
if (loggers != null) {
int len = ((Object[]) loggers).length;
if (len > 0) {
Object val;
StringBuilder sb = new StringBuilder();
for (int count = 0; count < len; count++) {
val = (((Object[]) loggers)[count]);
if ((val == null) || (val.toString().trim().length() == 0)) {
continue;
}
sb.append(sep).append(val);
sep = ",";
}
listOfModules = sb.toString();
}
}
// Add custom loggers
if ((customLoggers != null) && (customLoggers.toString().trim().length() != 0)) {
String customLoggerList = customLoggers.toString().trim();
for (String delim : CUSTOM_LOGGER_DELIMITERS) {
customLoggerList = customLoggerList.replace(delim, ",");
}
listOfModules += sep + customLoggerList;
}
if (!listOfModules.isEmpty()) {
attMap.put("listOfModules", listOfModules);
}
// Get the number to Display
if (numberToDisplay == null) {
numberToDisplay = DEFAULT_NUMBER_TO_DISPLAY;
}
// Get the direction
if (direction == null) {
direction = Boolean.FALSE;
}
// Get AfterRecord flag
if (after == null) {
// Not supplied, use direction
after = direction;
}
notNullStringPut(attMap, "logFileName", logFileName);
notNullStringPut(attMap, "startIndex", fromRecord);
notNullStringPut(attMap, "searchForward", after);//direction
notNullStringPut(attMap, "maximumNumberOfResults", numberToDisplay);
notNullStringPut(attMap, "onlyLevel", onlyLevel);
if (from != null) {
notNullStringPut(attMap, "fromTime", Long.valueOf(from.getTime()));
}
if (to != null) {
notNullStringPut(attMap, "toTime", Long.valueOf(to.getTime()));
}
notNullStringPut(attMap, "anySearch", anySearch);
notNullStringPut(attMap, "logLevel", logLevel);
notNullStringPut(attMap, "logFileRefresh", "true");
// if (moduleList != null) {
// attMap.addAll("listOfModules", moduleList);
// }
//notNullStringPut(attMap, "logFileRefresh", logFileName);
}
}
handlerCtx.setOutputValue("attributes", attMap);
}
/**
* This handler creates a Map<String, String> which contains the
* QUERY_STRING parameters that should be passed to the REST logging
* endpoint to make a query with the given constraints.
*
* @param context The HandlerContext.
*/
@Handler(id = "gf.processLogRecords",
input = {
@HandlerInput(name = "logRecords", type = List.class, required = true),
@HandlerInput(name = "truncate", type = Boolean.class, defaultValue = "true"),
@HandlerInput(name = "truncateLength", type = Integer.class, defaultValue = "100")},
output = {
@HandlerOutput(name = "result", type = List.class),
@HandlerOutput(name = "firstRecord", type = Integer.class),
@HandlerOutput(name = "lastRecord", type = Integer.class)})
public static void processLogRecords(HandlerContext handlerCtx) {
// Get the input...
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy