Search in sources :

Example 1 with MethodMetaData

use of org.glassfish.admin.rest.provider.MethodMetaData in project Payara by payara.

the class CollectionLeafResource method getMethodMetaData.

protected Map<String, MethodMetaData> getMethodMetaData() {
    Map<String, MethodMetaData> mmd = new TreeMap<String, MethodMetaData>();
    // GET meta data
    mmd.put("GET", new MethodMetaData());
    // POST meta data
    String postCommand = getPostCommand();
    if (postCommand != null) {
        MethodMetaData postMethodMetaData = ResourceUtil.getMethodMetaData(postCommand, locatorBridge.getRemoteLocator());
        mmd.put("POST", postMethodMetaData);
    }
    // DELETE meta data
    String deleteCommand = getDeleteCommand();
    if (deleteCommand != null) {
        MethodMetaData deleteMethodMetaData = ResourceUtil.getMethodMetaData(deleteCommand, locatorBridge.getRemoteLocator());
        mmd.put("DELETE", deleteMethodMetaData);
    }
    return mmd;
}
Also used : MethodMetaData(org.glassfish.admin.rest.provider.MethodMetaData) TreeMap(java.util.TreeMap)

Example 2 with MethodMetaData

use of org.glassfish.admin.rest.provider.MethodMetaData in project Payara by payara.

the class TemplateListOfResource method buildActionReportResult.

protected ActionReportResult buildActionReportResult() {
    if (entity == null) {
        // wrong resource
        String errorMessage = localStrings.getLocalString("rest.resource.erromessage.noentity", "Resource not found.");
        return ResourceUtil.getActionReportResult(ActionReport.ExitCode.FAILURE, errorMessage, requestHeaders, uriInfo);
    }
    RestActionReporter ar = new RestActionReporter();
    final String typeKey = (decode(getName(uriInfo.getPath(), '/')));
    ar.setActionDescription(typeKey);
    OptionsResult optionsResult = new OptionsResult(Util.getResourceName(uriInfo));
    Map<String, MethodMetaData> mmd = getMethodMetaData();
    optionsResult.putMethodMetaData("GET", mmd.get("GET"));
    optionsResult.putMethodMetaData("POST", mmd.get("POST"));
    ResourceUtil.addMethodMetaData(ar, mmd);
    ar.getExtraProperties().put("childResources", ResourceUtil.getResourceLinks(getEntity(), uriInfo));
    ar.getExtraProperties().put("commands", ResourceUtil.getCommandLinks(getCommandResourcesPaths()));
    // an internal impl detail, so it can wait
    return new ActionReportResult(ar, optionsResult);
}
Also used : ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) MethodMetaData(org.glassfish.admin.rest.provider.MethodMetaData) OptionsResult(org.glassfish.admin.rest.results.OptionsResult)

Example 3 with MethodMetaData

use of org.glassfish.admin.rest.provider.MethodMetaData in project Payara by payara.

the class TemplateRestResource method buildActionReportResult.

protected ActionReportResult buildActionReportResult(boolean showEntityValues) {
    RestActionReporter ar = new RestActionReporter();
    ar.setExtraProperties(new Properties());
    ConfigBean entity = (ConfigBean) getEntity();
    if (childID != null) {
        ar.setActionDescription(childID);
    } else if (childModel != null) {
        ar.setActionDescription(childModel.getTagName());
    }
    if (showEntityValues) {
        if (entity != null) {
            ar.getExtraProperties().put("entity", getAttributes(entity));
        }
    }
    OptionsResult optionsResult = new OptionsResult(Util.getResourceName(uriInfo));
    Map<String, MethodMetaData> mmd = getMethodMetaData();
    optionsResult.putMethodMetaData("GET", mmd.get("GET"));
    optionsResult.putMethodMetaData("POST", mmd.get("POST"));
    optionsResult.putMethodMetaData("DELETE", mmd.get("DELETE"));
    ResourceUtil.addMethodMetaData(ar, mmd);
    if (entity != null) {
        ar.getExtraProperties().put("childResources", ResourceUtil.getResourceLinks(entity, uriInfo, ResourceUtil.canShowDeprecatedItems(locatorBridge.getRemoteLocator())));
    }
    ar.getExtraProperties().put("commands", ResourceUtil.getCommandLinks(getCommandResourcesPaths()));
    return new ActionReportResult(ar, entity, optionsResult);
}
Also used : ActionReportResult(org.glassfish.admin.rest.results.ActionReportResult) RestActionReporter(org.glassfish.admin.rest.utils.xml.RestActionReporter) ConfigBean(org.jvnet.hk2.config.ConfigBean) MethodMetaData(org.glassfish.admin.rest.provider.MethodMetaData) Properties(java.util.Properties) OptionsResult(org.glassfish.admin.rest.results.OptionsResult)

Example 4 with MethodMetaData

use of org.glassfish.admin.rest.provider.MethodMetaData in project Payara by payara.

the class TemplateRestResource method getMethodMetaData.

private Map<String, MethodMetaData> getMethodMetaData() {
    Map<String, MethodMetaData> map = new TreeMap<String, MethodMetaData>();
    // GET meta data
    map.put("GET", new MethodMetaData());
    // ///optionsResult.putMethodMetaData("POST", new MethodMetaData());
    MethodMetaData postMethodMetaData = ResourceUtil.getMethodMetaData(childModel);
    map.put("POST", postMethodMetaData);
    // DELETE meta data
    String command = getDeleteCommand();
    if (command != null) {
        MethodMetaData deleteMethodMetaData;
        if (command.equals("GENERIC-DELETE")) {
            deleteMethodMetaData = new MethodMetaData();
        } else {
            deleteMethodMetaData = ResourceUtil.getMethodMetaData(command, locatorBridge.getRemoteLocator());
            // In case of delete operation(command), do not  display/provide id attribute.
            deleteMethodMetaData.removeParamMetaData("id");
        }
        map.put("DELETE", deleteMethodMetaData);
    }
    return map;
}
Also used : MethodMetaData(org.glassfish.admin.rest.provider.MethodMetaData) TreeMap(java.util.TreeMap)

Example 5 with MethodMetaData

use of org.glassfish.admin.rest.provider.MethodMetaData in project Payara by payara.

the class ResourceUtil method getMethodMetaData.

/**
 * Constructs and returns the resource method meta-data.
 *
 * @param command the command associated with the resource method
 * @param commandParamsToSkip the command parameters for which not to
 * include the meta-data.
 * @param habitat the habitat
 * @param logger the logger to use
 * @return MethodMetaData the meta-data store for the resource method.
 */
public static MethodMetaData getMethodMetaData(String command, HashMap<String, String> commandParamsToSkip, ServiceLocator habitat) {
    MethodMetaData methodMetaData = new MethodMetaData();
    if (command != null) {
        Collection<CommandModel.ParamModel> params;
        if (commandParamsToSkip == null) {
            params = getParamMetaData(command, habitat);
        } else {
            params = getParamMetaData(command, commandParamsToSkip.keySet(), habitat);
        }
        if (params != null) {
            Iterator<CommandModel.ParamModel> iterator = params.iterator();
            CommandModel.ParamModel paramModel;
            while (iterator.hasNext()) {
                paramModel = iterator.next();
                Param param = paramModel.getParam();
                ParameterMetaData parameterMetaData = getParameterMetaData(paramModel);
                String parameterName = (param.primary()) ? "id" : paramModel.getName();
                // If the Param has an alias, use it instead of the name
                String alias = param.alias();
                if (alias != null && (!alias.isEmpty())) {
                    parameterName = alias;
                }
                methodMetaData.putParameterMetaData(parameterName, parameterMetaData);
            }
        }
    }
    return methodMetaData;
}
Also used : Param(org.glassfish.api.Param) MethodMetaData(org.glassfish.admin.rest.provider.MethodMetaData) CommandModel(org.glassfish.api.admin.CommandModel) ParameterMetaData(org.glassfish.admin.rest.provider.ParameterMetaData)

Aggregations

MethodMetaData (org.glassfish.admin.rest.provider.MethodMetaData)13 TreeMap (java.util.TreeMap)5 ActionReportResult (org.glassfish.admin.rest.results.ActionReportResult)5 OptionsResult (org.glassfish.admin.rest.results.OptionsResult)5 RestActionReporter (org.glassfish.admin.rest.utils.xml.RestActionReporter)5 HashMap (java.util.HashMap)3 ParameterMetaData (org.glassfish.admin.rest.provider.ParameterMetaData)3 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 Properties (java.util.Properties)2 MultiException (org.glassfish.hk2.api.MultiException)2 Attribute (org.jvnet.hk2.config.Attribute)2 Map (java.util.Map)1 OPTIONS (javax.ws.rs.OPTIONS)1 Produces (javax.ws.rs.Produces)1 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)1 Param (org.glassfish.api.Param)1 CommandModel (org.glassfish.api.admin.CommandModel)1 ParameterMap (org.glassfish.api.admin.ParameterMap)1 ConfigBean (org.jvnet.hk2.config.ConfigBean)1