Search in sources :

Example 66 with Handler

use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.

the class JdbcTempHandler method setJDBCPoolWizard.

/**
 *	<p> This handler gets the default values and resource type and puts them in session
 */
@Handler(id = "setJDBCPoolWizard", input = { @HandlerInput(name = "fromStep2", type = Boolean.class), @HandlerInput(name = "attrMap", type = Map.class) }, output = { @HandlerOutput(name = "ResTypeList", type = java.util.List.class), @HandlerOutput(name = "DBVendorList", type = java.util.List.class) })
public static void setJDBCPoolWizard(HandlerContext handlerCtx) {
    // We need to use 2 maps for JDBC Connection Pool creation because there are extra info we need to keep track in
    // the wizard, but cannot be passed to the creation API.
    Boolean fromStep2 = (Boolean) handlerCtx.getInputValue("fromStep2");
    if ((fromStep2 != null) && fromStep2) {
    // wizardPool is already in session map
    } else {
        Map attrMap = (Map) handlerCtx.getInputValue("attrMap");
        Map sessionMap = handlerCtx.getFacesContext().getExternalContext().getSessionMap();
        sessionMap.put("wizardMap", attrMap);
        sessionMap.put("wizardPoolExtra", new HashMap());
    // sessionMap.put("wizardPoolProperties", new HashMap());
    }
    handlerCtx.setOutputValue("ResTypeList", resTypeList);
    handlerCtx.setOutputValue("DBVendorList", dbVendorList);
}
Also used : HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) Handler(com.sun.jsftemplating.annotation.Handler)

Example 67 with Handler

use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.

the class LogViewHandlers method getLogQueryAttributes.

/**
 * <p> This handler creates a Map&lt;String, String&gt; which contains the
 * QUERY_STRING parameters that should be passed to the REST logging
 * endpoint to make a query with the given constraints.</p>
 *
 * @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<String, Object> attMap = new HashMap<String, Object>();
    // 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);
            // direction
            notNullStringPut(attMap, "searchForward", after);
            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);
}
Also used : HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Date(java.util.Date) Handler(com.sun.jsftemplating.annotation.Handler)

Example 68 with Handler

use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.

the class LogViewHandlers method processLogRecords.

/**
 * <p> This handler creates a Map&lt;String, String&gt; which contains the
 * QUERY_STRING parameters that should be passed to the REST logging
 * endpoint to make a query with the given constraints.</p>
 *
 * @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<Map<String, Object>> records = (List<Map<String, Object>>) handlerCtx.getInputValue("logRecords");
    if (records != null) {
        // Make sure there's something to do...
        boolean truncate = (Boolean) handlerCtx.getInputValue("truncate");
        int truncLen = (Integer) handlerCtx.getInputValue("truncateLength");
        Locale locale = GuiUtil.getLocale();
        // Loop through the records...
        for (Map<String, Object> record : records) {
            record.put("dateTime", formatDateForDisplay(locale, new Date(Long.parseLong(record.get("loggedDateTimeInMS").toString()))));
            /*
                 // FIXME: Should we add this code back in?  It was not being
                 // FIXME: used in the current version.
                 String msgId = (String) row.getMessageID();
                 String level = (String) row.getLevel();
                 String moduleName = (String)row.getModule();
                 //only SEVERE msg provoides diagnostic info.
                 if (level.equalsIgnoreCase("severe")) {
                 // NOTE: Image name/location is hard-coded
                 record.put("levelImage", GuiUtil.getMessage("common.errorGif"));
                 record.put(SHOW_LEVEL_IMAGE, new Boolean(true));
                 record.put("diagnosticCauses", getDiagnosticCauses(handlerCtx, msgId, moduleName));
                 record.put("diagnosticChecks", getDiagnosticChecks(handlerCtx, msgId, moduleName));
                 //                        record.put("diagnosticURI", getDiagnosticURI(handlerCtx, msgId));
                 } else {
                 record.put(SHOW_LEVEL_IMAGE, new Boolean(false));
                 record.put("diagnostic", "");
                 }
                 record.put("level", level);
                 record.put("productName", row.getProductName());
                 record.put("logger", moduleName);
                 */
            String message = ((String) record.get("message")).trim();
            if (truncate && (message.length() > truncLen)) {
                message = message.substring(0, truncLen).concat("...\n");
            }
            record.put("message", Util.htmlEscape(message));
        }
    }
    // Set the first / last record numbers as attributes
    if ((records != null) && (records.size() > 0)) {
        handlerCtx.setOutputValue("firstRecord", records.get(0).get("recordNumber"));
        handlerCtx.setOutputValue("lastRecord", records.get(records.size() - 1).get("recordNumber"));
    // hasResults = true;
    } else {
        handlerCtx.setOutputValue("firstRecord", "-1");
        handlerCtx.setOutputValue("lastRecord", "-1");
    }
    handlerCtx.setOutputValue("result", records);
}
Also used : Locale(java.util.Locale) List(java.util.List) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Map(java.util.Map) Date(java.util.Date) Handler(com.sun.jsftemplating.annotation.Handler)

Example 69 with Handler

use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.

the class MonitoringHandlers method addToMonitorList.

/**
 *	<p> Add list to new list
 */
@Handler(id = "addToMonitorList", input = { @HandlerInput(name = "oldList", type = List.class), @HandlerInput(name = "newList", type = List.class) }, output = { @HandlerOutput(name = "result", type = List.class) })
public static void addToMonitorList(HandlerContext handlerCtx) {
    List<String> oldList = (List) handlerCtx.getInputValue("oldList");
    List<String> newList = (List) handlerCtx.getInputValue("newList");
    if (newList == null) {
        newList = new ArrayList();
    }
    if (oldList != null) {
        for (String sk : oldList) {
            newList.add(sk);
        }
    }
    handlerCtx.setOutputValue("result", newList);
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Handler(com.sun.jsftemplating.annotation.Handler)

Example 70 with Handler

use of com.sun.jsftemplating.annotation.Handler in project Payara by payara.

the class MonitoringHandlers method updateMonitorLevels.

@Handler(id = "updateMonitorLevels", input = { @HandlerInput(name = "allRows", type = List.class, required = true), @HandlerInput(name = "endpoint", type = String.class) })
public static void updateMonitorLevels(HandlerContext handlerCtx) {
    String endpoint = (String) handlerCtx.getInputValue("endpoint");
    List<Map> allRows = (List<Map>) handlerCtx.getInputValue("allRows");
    Map payload = new HashMap();
    for (Map<String, String> oneRow : allRows) {
        payload.put(oneRow.get("attrName"), oneRow.get("level"));
    }
    try {
        RestUtil.restRequest(endpoint, payload, "post", null, false);
    } catch (Exception ex) {
        GuiUtil.getLogger().severe(GuiUtil.getCommonMessage("msg.error.save.monitor.modules", new Object[] { endpoint, payload }));
        GuiUtil.handleError(handlerCtx, GuiUtil.getMessage("msg.error.checkLog"));
        return;
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Handler(com.sun.jsftemplating.annotation.Handler)

Aggregations

Handler (com.sun.jsftemplating.annotation.Handler)167 ArrayList (java.util.ArrayList)85 Map (java.util.Map)85 List (java.util.List)82 HashMap (java.util.HashMap)81 TreeMap (java.util.TreeMap)14 IOException (java.io.IOException)12 Date (java.util.Date)9 ConnectorRuntimeException (com.sun.appserv.connectors.internal.api.ConnectorRuntimeException)8 LayoutViewHandler (com.sun.jsftemplating.layout.LayoutViewHandler)8 Image (com.sun.pkg.client.Image)8 ListIterator (java.util.ListIterator)8 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 FacesContext (javax.faces.context.FacesContext)7 AttributeList (javax.management.AttributeList)7 RestResponse (org.glassfish.admingui.common.util.RestResponse)7 URL (java.net.URL)6 IntegrationPoint (org.glassfish.admingui.connector.IntegrationPoint)6 MultipleListDataProvider (com.sun.jsftemplating.component.dataprovider.MultipleListDataProvider)5 TableRowGroup (com.sun.webui.jsf.component.TableRowGroup)5