Search in sources :

Example 26 with Handler

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

the class JmsHandlers method updatePhysicalDestination.

/**
 * <p>This handler updates a physical destination.</p>
 * @param context The HandlerContext.
 */
@Handler(id = "updatePhysicalDestination", input = { @HandlerInput(name = "name", type = String.class, required = true), @HandlerInput(name = "attributes", type = Map.class, required = true), @HandlerInput(name = "type", type = String.class) })
public static void updatePhysicalDestination(HandlerContext handlerCtx) {
    try {
        final String type = (String) handlerCtx.getInputValue("type");
        final String name = (String) handlerCtx.getInputValue("name");
        AttributeList list = new AttributeList();
        // Copy attributes to the AttributeList.
        // Make it work, then make it right. :|
        Map attrMap = (Map) handlerCtx.getInputValue("attributes");
        buildAttributeList(list, attrMap, type);
        String objectName = getJmsDestinationObjectName(SUBTYPE_CONFIG, name, type);
        JMXUtil.getMBeanServer().setAttributes(new ObjectName(objectName), list);
    } catch (Exception ex) {
        GuiUtil.handleException(handlerCtx, ex);
    }
}
Also used : AttributeList(javax.management.AttributeList) HashMap(java.util.HashMap) Map(java.util.Map) ConnectorRuntimeException(com.sun.appserv.connectors.internal.api.ConnectorRuntimeException) ObjectName(javax.management.ObjectName) Handler(com.sun.jsftemplating.annotation.Handler)

Example 27 with Handler

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

the class PayaraUtilHandlers method mapRemove.

/**
 * @param context
 */
@Handler(id = "mapRemove", input = { @HandlerInput(name = "map", type = Map.class, required = true), @HandlerInput(name = "key", type = Object.class, required = true) })
public static void mapRemove(HandlerContext context) {
    Map map = (Map) context.getInputValue("map");
    Object key = context.getInputValue("key");
    map.remove(key);
}
Also used : Map(java.util.Map) Handler(com.sun.jsftemplating.annotation.Handler)

Example 28 with Handler

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

the class PayaraRestApiHandlers method getRestEndpoints.

/**
 * Gets the REST endpoints from a given app name and optional component name
 * @param handlerCtx
 */
@Handler(id = "py.getRestEndpoints", input = { @HandlerInput(name = "appName", type = String.class, required = true), @HandlerInput(name = "componentName", type = String.class, required = false) }, output = { @HandlerOutput(name = "result", type = java.util.List.class) })
public static void getRestEndpoints(HandlerContext handlerCtx) {
    List<Map<String, String>> result = new ArrayList<>();
    try {
        String appName = (String) handlerCtx.getInputValue("appName");
        String encodedAppName = URLEncoder.encode(appName, "UTF-8");
        String componentName = (String) handlerCtx.getInputValue("componentName");
        String encodedComponentName = URLEncoder.encode(componentName, "UTF-8");
        String prefix = GuiUtil.getSessionValue("REST_URL") + "/applications/application/" + encodedAppName;
        // get the extra properties from the list-rest-endpoints command, passing in the component name
        Map attrMap = new HashMap();
        attrMap.put("componentname", encodedComponentName);
        Map payaraEndpointDataMap = RestUtil.restRequest(prefix + "/list-rest-endpoints", attrMap, "GET", null, false, false);
        Map payaraEndpointsExtraProps = (Map) ((Map) ((Map) payaraEndpointDataMap.get("data")).get("extraProperties"));
        // Check if the command returned any endpoints
        if (payaraEndpointsExtraProps.get("endpoints") != null) {
            Map<String, List<String>> output = (Map<String, List<String>>) payaraEndpointsExtraProps.get("endpoints");
            output.forEach((path, methods) -> {
                methods.forEach(method -> {
                    Map<String, String> endpointDetails = new TreeMap<>();
                    endpointDetails.put("endpointPath", path);
                    endpointDetails.put("requestMethod", method);
                    result.add(endpointDetails);
                });
            });
        }
    } catch (Exception ex) {
        GuiUtil.getLogger().info(GuiUtil.getCommonMessage("log.error.getRestEndpoints") + ex.getLocalizedMessage());
        if (GuiUtil.getLogger().isLoggable(Level.FINE)) {
            ex.printStackTrace();
        }
    }
    handlerCtx.setOutputValue("result", result);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) Handler(com.sun.jsftemplating.annotation.Handler)

Example 29 with Handler

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

the class UtilHandlers method convertStringtoListHandler.

/**
 *	<p> This handler takes in a string with delimiter and returns list
 * @param handlerCtx
 */
@Handler(id = "convertStringtoList", input = { @HandlerInput(name = "str", type = String.class), @HandlerInput(name = "delimiter", type = String.class, defaultValue = ",") }, output = { @HandlerOutput(name = "result", type = List.class) })
public static void convertStringtoListHandler(HandlerContext handlerCtx) {
    List result = convertStringToList((String) handlerCtx.getInputValue("str"), (String) handlerCtx.getInputValue("delimiter"));
    handlerCtx.setOutputValue("result", result);
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Handler(com.sun.jsftemplating.annotation.Handler)

Example 30 with Handler

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

the class UtilHandlers method convertMapToListOfMap.

/**
 *	This method converts a Map into a list of Map with keyName and ValueName.  This is suitable for table display.
 * @param handlerCtx
 */
@Handler(id = "gf.convertMapToListOfMap", input = { @HandlerInput(name = "map", type = Map.class, required = true), @HandlerInput(name = "keyName", type = String.class, defaultValue = "key"), @HandlerInput(name = "valueName", type = String.class, defaultValue = "value") }, output = { @HandlerOutput(name = "result", type = List.class) })
public static void convertMapToListOfMap(HandlerContext handlerCtx) {
    Map map = ((Map) handlerCtx.getInputValue("map"));
    String keyName = ((String) handlerCtx.getInputValue("keyName"));
    String valueName = ((String) handlerCtx.getInputValue("valueName"));
    List result = new ArrayList();
    for (Map.Entry entry : (Set<Map.Entry>) map.entrySet()) {
        Map oneRow = new HashMap();
        oneRow.put(keyName, entry.getKey());
        oneRow.put(valueName, entry.getValue());
        result.add(oneRow);
    }
    handlerCtx.setOutputValue("result", result);
}
Also used : Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) 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